开发者

Basic Django - Custom Managers

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 Da开发者_如何学Pythonhl')

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜