开发者

Basic Django - Custom Managers

开发者 https://www.devze.com 2022-12-20 14:33 出处:网络
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:

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

精彩评论

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

关注公众号