Actually we know super
is used to find the "parent class" and return its object, something like/using self.__class__.__mro__
What I was confused about is when to use it exactly?
Suppose we have a Example model code as below
version_1
class Example(models.Model):
name = models.CharField()
age = models.IntegerField()
def save(self, **args, **kwargs):
obj = super(Example, self).save(self, **args, **kwargs)
obj.name = "name changed"
obj.age = "age changed"
return obj
version_2
class Example(models.Model):
name = models.CharField()
age = models.IntegerField()
def save(self, **args, **kwargs):
self.name = "name changed"
self.age = "age changed"
obj = super(Example, self).save(self, **args, **kwargs)
return obj
so as we can observe above
In version_1 I have called super
first and done modifications to fields and returned the obj
In version_2 I had modified the fields and after that called super and returned obj
So what happens when super is called before and after modification of fields?
Finally what i want to know/confirm is
- Where/why exactly super is used in django forms/models.
- What is the exact concept of using them in django / python (if I understood this wrong).