tags:

views:

49

answers:

2

I'm going through the Django book and I'm currently on chapter 10. I'm having a problem understanding the third line in this fragment of code:

class DahlBookManager(models.Manager):
    def get_query_set(self):
        return super(DahlBookManager, self).get_query_set().filter(author='Roald Dahl')

I understand that this custom manager instance is overriding the superclass' get_query_set method, but why is the super call passing in both DahlBookManager as well as self? Aren't self and DahlBookManager the same thing?

A: 

No, self is an instance of DahlBookManager. super() uses the class to handle things like MRO, inheritance, etc.

Ignacio Vazquez-Abrams
A: 

This is about the builtin Super() function in Python.

You can get a reference here: http://docs.python.org/library/functions.html

If the second argument is omitted, the super object returned is unbound.

CNBorn