1๐
โ
Add a custom save method to your model class. Sample code below will automatically compute expiry date only upon creation. Subsequent modification of the record will not trigger this automatic computation.
class ModelName(models.Model):
created = models.DateTimeField()
expired = models.DateTimeField(blank=True, null=True)
def save(self, *args, **kwargs):
if not self.pk:
self.expired = self.created + datetime.timedelta(days=30)
super(ModelName, self).save(*args, **kwargs)
๐คWannabe Coder
0๐
if u want to use the solution above, it better for your code to use signals:
https://docs.djangoproject.com/en/1.8/ref/signals/#post-save
๐คHetdev
Source:stackexchange.com