Tuesday, November 10, 2015

Django override save method

Django override save method (two ways)



1)
 class Blog(models.Model):
  name = models.CharField(max_length=100)
  tagline = models.TextField()

  def save(self, *args, **kwargs):
    do_something()
   # Call the "real" save() method in the base class 'models.Model'
    super(Blog, self).save(*args, **kwargs) <-----
    do_something_else()

 is equal to

2)
  class Blog(models.Model):
   name = models.CharField(max_length=100)
   tagline = models.TextField()

   def save(self, *args, **kwargs):
     do_something()
    # Call the "real" save() method in the base class 'models.Model'.
     models.Model.save(self, *args, **kwargs) <----- Note: self
     do_something_else()

2 comments:

  1. It’s the best time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I want to suggest you few interesting things or suggestions.You can write next articles referring to this article. I desire to read even more things about it..
    SAP HR Training in Chennai
    SAP ABAP Training in Chennai
    SAP FICO Training in Chennai

    ReplyDelete
  2. Robotic Process Automation (RPA) is one of the most exciting developments in Business Process Management (BPM) in recent history. Some industry experts believe it may be even more transformational than cloud computing transformational than cloud Automationminds team. (RPA)Automationminds lets you program in (RPA),
    Robotic Process Automation course bluePrism

    ReplyDelete