Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

custom save django

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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #custom #save #django
ADD COMMENT
Topic
Name
5+4 =