django 查询过滤的问题

这种形式能完成查询一个属性有多个值的情况

User.objects.filter(username__in=['user1','user2'])

同样这个也可以

groups = Group.objects.filter(player=p1).filter(player=p2)

如果你要查询一个更复杂的情况

filter_dict = disc()
把相关值打包放进去

User.objects.filter(**filter_disc)

#我查到另外一个但是不行!

class AppRightManageListView(ListView): template_name = ‘rightmanage/list_apprightmanage.html’ # model = DeployPool paginate_by = 50

def get_queryset(self):
    filter_dict = dict()
    if self.request.GET.get('search_pk'):
        filter_dict['name__contains'] = self.request.GET.get('search_pk')
    if self.request.GET.get('app_name'):
        filter_dict['id'] = self.request.GET.get('app_name')
    if self.request.GET.get('site_name'):
        app_id_list = []
        site = Site.objects.get(id=self.request.GET.get('site_name'))
        for app in site.app_name.all():
            app_id_list.append(app.id)
        filter_dict['id__in'] = app_id_list
    return App.objects.filter(**filter_dict)