通过字典传递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)

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

上一篇:CentOS7下MySQL5.7重置root密码方法


下一篇:exchange 2013 的owa重定向设置