通过字典传递django orm的filter功能

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)

posted @ 2017-03-14 16:54 aguncn 阅读(...) 评论(...) 编辑 收藏