Skip to content

Using django-filter with class-based views #1369

Answered by carltongibson
perlun asked this question in Q&A
Discussion options

You must be logged in to vote

Take a look at the bundled generic view implementation:

def get(self, request, *args, **kwargs):
filterset_class = self.get_filterset_class()
self.filterset = self.get_filterset(filterset_class)
if not self.filterset.is_bound or self.filterset.is_valid() or not self.get_strict():
self.object_list = self.filterset.qs
else:
self.object_list = self.filterset.queryset.none()
context = self.get_context_data(filter=self.filterset,
object_list=self.object_list)
return self.render_to_response(context)

It should give you the guidance you need.

In general you…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@perlun
Comment options

@perlun
Comment options

Answer selected by perlun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1368 on April 29, 2021 17:41.