Django:管理链式过滤

时间:2014-03-24 12:18:25

标签: django filtering admin chained

我想进行链式过滤但不起作用

def queryset(self, request):
   qs = super(MaterialAdmin, self).queryset(request)
   if request.user.is_superuser:
       self.exclude = []
       return qs
   else:
       self.exclude = ['droits_acces', 'groupe']


   ff = qs.filter(groupe= request.user)
   gg = qs.filter(user=request.user)

   jj = qs.filter(user=request.user).filter(groupe= request.user)

   return jj

怎么办?

ff = [CC409,ST54]

gg = [Al2O3,BB79,CC409]

我想

jj = [CC409,ST54,Al2O3,BB79]

1 个答案:

答案 0 :(得分:0)

您可以使用the Q object进行复杂查询。

from django.db.models import Q

...
    def queryset(self, request):
    ...
    return qs.filter(Q(groupe=request.user)|Q(user=request.user))