Using django-filter with class-based views #1369
-
Hi, The docs are pretty clear on how to use this library with traditional Django views: def product_list(request):
filter = ProductFilter(request.GET, queryset=Product.objects.all())
return render(request, 'my_app/template.html', {'filter': filter}) However, we are not using function-based views in our application but class-based views. I have tried various approaches on trying to get this working but I really don't get it. Here's my last attempt: class CustomersView(LoginRequiredMixin):
queryset = Customer.objects.all()
filter = CustomerFilter(self.request, queryset=self.queryset) Obviously, this can't work since I've also tried various approaches which involved overriding def get_queryset(self):
filter = CustomerFilter(self.request, queryset=self.queryset)
return self.queryset.filter(filter) But with this I'm getting an error |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Take a look at the bundled generic view implementation: django-filter/django_filters/views.py Lines 76 to 88 in 2b2c13d It should give you the guidance you need. In general you access the filtered QuerySet via |
Beta Was this translation helpful? Give feedback.
Take a look at the bundled generic view implementation:
django-filter/django_filters/views.py
Lines 76 to 88 in 2b2c13d
It should give you the guidance you need.
In general you…