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 :: how to make a list string in python 
Python :: extend a list python 
Python :: spacy config 
Python :: python left rotation 
Python :: odoo scaffold 
Python :: tkinter prevent window resize 
Python :: write a python program to find table of a number using while loop 
Python :: only get top 10 python dataframe 
Python :: isnull().mean() python 
Python :: multiply each element in list python 
Python :: how to remove numbers from a dataframe in python 
Python :: python find index by value 
Python :: python count bits 
Python :: python num perfect squares 
Python :: python plot multiple lines in same figure 
Python :: import math sqrt python 
Python :: Make a basic pygame window 
Python :: python ssh into server 
Python :: basic tkinter window 
Python :: convert float in datetime python 
Python :: basic pygame window 
Python :: get range of items of python list 
Python :: Delete file in python Using the os module 
Python :: python get memory address 
Python :: conda environment 
Python :: select a range of rows in pandas dataframe 
Python :: tasks discord py 
Python :: python average of list 
Python :: datetime library 
Python :: python tkinter colored line 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =