but he is returning directly the chackou and I want that only if it is chosen returns him
I'll simplify it so I can understand it, I need it in model.py, when the person chooses the "SIM" option that adds and updates the chekout with datatimenow, but I can not do it
Model.py
SAIDA_CHOICES = (
('Não', 'Não Pago'),
('Sim', 'Pago')
)
class MovRotativo(models.Model):
checkin = models.DateTimeField(auto_now=True, blank=False, null=False,)
checkout = models.DateTimeField(auto_now=True, null=True, blank=True)
email = models.EmailField(blank=False)
placa = models.CharField(max_length=7, blank=False)
modelo = models.CharField(max_length=15, blank=False)
valor_hora = models.DecimalField(
max_digits=5, decimal_places=2, null=False, blank=False)
pago = models.CharField(max_length=15, choices=PAGO_CHOICES)
chk = models.CharField(max_length=15, choices=SAIDA_CHOICES)
def saida(self):
if self.chk == 'sim':
return self.chk
else:
self.checkout = models.DateTimeField(auto_now=True)
return self.checkout