How to call super of enclosing class in a mixin in Python?
<p>I have the following code, in Django:</p>

<pre><code>class Parent(models.Model):
    def save(self):
        # Do Stuff A

class Mixin(object):
    def save(self):
        # Do Stuff B

class A(Parent, Mixin):
    def save(self):
        super(A, self).save()
        # Do stuff C
</code></pre>

<p>Now, I want to use the mixin without blatting the behaviour of the save in Parent. So I when I save, I want to do stuff C, B, and A. I've read <a href="http://stackoverflow.com/questions/27664632/calling-the-setter-of-a-super-class-in-a-mixin">Calling the setter of a super class in a mixin</a> however I don't get it and having read the super docs it doesn't seem to answer my question.</p>

<p>THe question is, what do I put in the mixin to make sure it does stuff B and doesn't stop Stuff A from happening?</p>

<p>How about calling super in your mixin class?</p>

<pre><code>class Parent(object):
    def test(self):
        print("parent")


class MyMixin(object):
    def test(self):
        super(MyMixin, self).test()
        print("mixin")


class MyClass(MyMixin, Parent):
    def test(self):
        super(MyClass, self).test()
        print("self")

if __name__ == "__main__":
    my_obj = MyClass()
    my_obj.test()
</code></pre>

<p>This will give you the output as:</p>

<pre><code>$ python test.py
parent
mixin
self
</code></pre>

python