[Answer]-Changing save or put functions in database orms

1👍

You’re just witnessing a method being overridden in a subclass. The purpose of subclassing is to reuse code and override functionality as necessary. Sometimes, that involves overriding a method and calling pieces of its parent.

super calls the parent class’s method.

This is exactly the same as doing no subclassing at all:

def save(...):
   return super(MyClass, self).save(...)

Conversely, if we just wrote a method without a super call, it would replace the parent class method functionality completely.

def save(...):
   print ("I have nothing to do with my parent class")

If we want to supplement functionality (i.e. keep the old behavior but add something extra in) we use super to call the original method from within the new method.

def save(...):
   print ("I am called directly before the original parent method")
   return super(MyClass, self).save(...)

Leave a comment