Django Manager Chaining

前端 未结 4 2106
独厮守ぢ
独厮守ぢ 2021-01-30 09:19

I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I\'ll expla

4条回答
  •  庸人自扰
    2021-01-30 09:51

    See this snippet on Djangosnippets: http://djangosnippets.org/snippets/734/

    Instead of putting your custom methods in a manager, you subclass the queryset itself. It's very easy and works perfectly. The only issue I've had is with model inheritance, you always have to define the manager in model subclasses (just: "objects = QuerySetManager()" in the subclass), even though they will inherit the queryset. This will make more sense once you are using QuerySetManager.

提交回复
热议问题