Search
 
SCRIPT & CODE EXAMPLE
 

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)
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 :: smallest string with a given numeric value 
Python :: python autorun script 
Python :: como agregar una fila a un dataframe con pandas 
Python :: gricsearchcv sample_weights 
Python :: rename multiple value in column in pandas 
Python :: if elif ladder in one line in python 
Python :: How to Empty a Set in Python Using the clear() Method 
Python :: Creating a Tuple with Mixed Datatypes. 
Python :: Count the number of Missing Values in the DataFrame 
Python :: excel win32com select multiple cells in a row or column 
Python :: Python Tkinter PanedWindow Widget Syntax 
Python :: percent change pandas using log 
Python :: Adding new nested object using Shallow copy 
Python :: The float type in Python3 can represent decimal 0.1 without error. 
Python :: change value of element 
Python :: valueerror python list 
Python :: convert set to list python time complexity method 2 
Python :: metros para cm para mm 
Python :: get database image in dajngo 
Python :: python how to tell if class is initialized 
Python :: python run only when list is bigger 
Python :: python pattern glob extension searching 
Python :: cgi in python; get() method 
Python :: frequency domain parameter of speech 
Python :: string times python 
Python :: odoo site map for employees hierarchy 
Python :: RuntimeError: input must have 3 dimensions, got 4 site:stackoverflow.com 
Python :: pip unknown command import 
Python :: pymol load coords 
Python :: Reading from a file way03 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =