I'v been trying to add 10 days in a django model.
I want to make this everytime a data is created in the DB.
expiration = 10
expiration_at = date of creation + expiration
EDITED
After some codes from comments. I got this so far.
class Certificados(models.Model):
username = models.CharField(max_length=30, unique=True, null=False)
name = models.CharField(max_length=255, null=False)
description = models.TextField(null=True)
created_at = models.DateTimeField(auto_now=True)
updated_at = models.DateTimeField(auto_now=True)
expiration = models.PositiveIntegerField()
expiration_at = models.DateTimeField()
def save(self, *args, **kwargs):
self.expiration_at = self.created_at + timedelta(days=self.expiration)
class Meta:
db_table = 'Certificados'
def __str__(self):
return self.username
This code now brings me this error.
Someone knows what is wrong?
