We can override the save method into 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()
No comments:
Post a Comment