from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin from django.db import models import datetime from django.core.validators import MaxValueValidator, MinValueValidator from django.utils.translation import gettext_lazy as _ from .managers import ReyMotaUserManager def current_year(): return datetime.date.today().year def max_value_current_year(value): return MaxValueValidator(current_year())(value) class Vehiculo(models.Model): marca = models.CharField(max_length=200) modelo = models.CharField(max_length=200) matricula = models.CharField(max_length=200) foto = models.ImageField(upload_to='vehiculos/', blank=True, null=True) # Nuevo campo def __str__(self): return self.marca class Repostaje(models.Model): vehiculo = models.ForeignKey(Vehiculo, on_delete=models.CASCADE) fecha = models.DateField() kms = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True) litros = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) descuento = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) importe = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) precioxlitro = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) kmsrecorridos = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True) consumo = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) def __str__(self): return self.fecha class ReyMotaUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(_("email address"), unique=True) foto = models.ImageField(upload_to="profile_images", blank=True) is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=True) nombre = models.CharField(max_length=200, blank=True, null=True) USERNAME_FIELD = "email" REQUIRED_FIELDS = [] objects = ReyMotaUserManager() def __str__(self): return self.email