Answers for "django custom save method"

0

django custom save method

from datetime import timedelta
# custom save model
def save(self, *args, **kwargs):
    # figure out warranty end date
    if self.warranty_period_type == 'm':
        self.warranty_end_date = self.purchase_date + timedelta(days=self.warranty_period_number*31)
    else:
        self.warranty_end_date = self.purchase_date + timedelta(days=self.warranty_period_number*365.2425)
    super(Purchase, self).save(*args, **kwargs)
Posted by: Guest on February-17-2022

Code answers related to "django custom save method"

Python Answers by Framework

Browse Popular Code Answers by Language