0

I am new to Django. I just move from c++. I have a question when I want to override a class method. Why do we need to call the current class name? for example

class MyStuff( models.Model ):

     def __init__(self, *args, **kwargs):
        super(MyStuff, self).__init__(*args, **kwargs)  #calling super "MyStuff" instead of "Model"

I am not sure how does Django work deep inside. Why don't we call super(Model, self)? How can I call Grandparent method?

Paulo Bu
  • 29,294
  • 6
  • 74
  • 73
MooMoo
  • 1,086
  • 12
  • 22
  • 2
    Your question is about python, not django. and this isn't a class method. – Leandro Jan 28 '14 at 16:26
  • The canonical guide to `super` (link taken from Python's official docs): [Python’s super() considered super](http://rhettinger.wordpress.com/2011/05/26/super-considered-super/) – lanzz Jan 28 '14 at 16:31

1 Answers1

0

See this answer

when you do super(MyStuff, self).__init__(*args, **kwargs) you are calling a instance method of the 'parent'

In python, you have multiple inherance, so when you call super(), the Method Resolution Order is not to just one parent, because you have multiples parents. See here

hope helps

Community
  • 1
  • 1
Leandro
  • 2,217
  • 15
  • 18