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

时间:2022-09-30 08:49:04
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功能