dkoug Blog

Dynamic queryset

Django -- Posted on Aug. 22, 2017

Dynamic queryset class based view django

1
2
3
4
5
6
7
def get_queryset(self):
   qs = super().get_queryset()
   model = self.model
   kwargs = dict((field, value) for field, value
                      in self.request.GET.items() if value)
   qs = model.objects.filter(**kwargs)
   return qs