Ticket #12338: django-models-doc.diff
File django-models-doc.diff, 1.3 KB (added by , 15 years ago) |
---|
-
docs/topics/db/models.txt
726 726 name = models.CharField(max_length=100) 727 727 tagline = models.TextField() 728 728 729 def save(self, force_insert=False, force_update=False):729 def save(self, *args, **kwargs): 730 730 do_something() 731 super(Blog, self).save( force_insert, force_update) # Call the "real" save() method.731 super(Blog, self).save(*args, **kwargs) # Call the "real" save() method. 732 732 do_something_else() 733 733 734 734 You can also prevent saving:: … … 737 737 name = models.CharField(max_length=100) 738 738 tagline = models.TextField() 739 739 740 def save(self, force_insert=False, force_update=False):740 def save(self, *args, **kwargs): 741 741 if self.name == "Yoko Ono's blog": 742 742 return # Yoko shall never have her own blog! 743 743 else: 744 super(Blog, self).save( force_insert, force_update) # Call the "real" save() method.744 super(Blog, self).save(*args, **kwargs) # Call the "real" save() method. 745 745 746 746 It's important to remember to call the superclass method -- that's that 747 747 ``super(Blog, self).save()`` business -- to ensure that the object still gets