Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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