Can anyone explain the overidding of save() of below code?

30 views
Skip to first unread message

Utpal Brahma

unread,
Mar 21, 2018, 11:52:36 AM3/21/18
to Django users
/* also explain super ().save() */

from django.db import models

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

def save(self, *args, **kwargs):
do_something()
super(Blog, self).save(*args, **kwargs) # Call the "real" save() method.
do_something_else()

Vinicius Assef

unread,
Mar 21, 2018, 1:20:12 PM3/21/18
to django...@googlegroups.com
You are calling save() in parent class. Read more about it here:
https://docs.python.org/3/library/functions.html?highlight=super#super
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3cd4d81a-2660-4b0c-aab1-2ef38cc65335%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Utpal Brahma

unread,
Mar 21, 2018, 4:19:46 PM3/21/18
to Django users
Thanks Vinicius Assef

Reply all
Reply to author
Forward
0 new messages