Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django action when create model

# override create model method (django)

class MyModel(models.Model):
  name = ....
  ........
  .......
  def save(self, *args, **kwargs):
      if not self.pk:
          # This code only happens if the objects is
          # not in the database yet. Otherwise it would
          # have pk
          
          # -- do your custom actions here --
          
      super(MyModel, self).save(*args, **kwargs) # activate the default method on update
Comment

PREVIOUS NEXT
Code Example
Python :: python script to write dataframe on excel 
Python :: onehot encode list of columns pandas 
Python :: class method in python 
Python :: python floor float 
Python :: pytest monkeypatch 
Python :: numpy linspace function 
Python :: python decorator class method 
Python :: python : a counter 
Python :: lambda functions python 
Python :: Use operator in python list 
Python :: pandas df number of columns 
Python :: os.path.join 
Python :: convert mixed number string to float 
Python :: test pypi 
Python :: Python NumPy ravel function Syntax 
Python :: python webview 
Python :: python shift number 
Python :: pyhon sort a list of tuples 
Python :: django for beginners 
Python :: pybase64 
Python :: hash table data structure python 
Python :: .extend python 
Python :: linear search algorithm in python 
Python :: split dataframe row on delimiter python 
Python :: how to create templates in python 
Python :: numpy.dot 
Python :: setup vs code for python 
Python :: indefinite loops python 
Python :: replace NaN value in pandas data frame 
Python :: load py file converted from .ui file 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =