Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

custom save method django

def save(self, *args, **kwargs):
    if self.id:
        print('updating')
    else:
        print('creating')
    super(Post, self).save(*args, **kwargs)
Comment

custom save method django

def save(self, *args, **kwargs):
   if self.title == “i dont like coding”:
       return  # instance not save
   self.slug = slugify(self.title)
   super(Post, self).save(*args, **kwargs)
Comment

PREVIOUS NEXT
Code Example
Python :: python subprocess stdout to dev null 
Python :: how to get dummies in a dataframe pandas 
Python :: heroku python version 
Python :: transpose matrix numpy 
Python :: Save a Dictionary to File in Python Using the dump Function of the pickle Module 
Python :: pandas select 2nd row 
Python :: how to start a new django project 
Python :: read files and write into another files python 
Python :: python font 
Python :: create virtual environment python 
Python :: groupby count pandas 
Python :: python find item in list 
Python :: Iterating With for Loops in Python Using range() and len() 
Python :: delete columns pandas 
Python :: remove punctuation python 
Python :: np.random 
Python :: reading json file in python 
Python :: convert string of list to list python 
Python :: prime number in python 
Python :: how to install neat 
Python :: imread real color cv2 
Python :: pyhon random number 
Python :: dataframe to dictionary 
Python :: how to check an element in a list in python 
Python :: numpy is not nan 
Python :: custom validation in django models 
Python :: python string slicing 
Python :: python mean 
Python :: plot second y axis matplotlib 
Python :: como transformar texto a audio y reproducirlo en pyrthon 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =