Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class MultipleObjectBaseView(MultipleObjectMixin, BaseView):
Base class for generic views onto a queryset.
pagination_serializer_class = api_settings.PAGINATION_SERIALIZER
paginate_by = api_settings.PAGINATE_BY
filter_class = None
filter_fields = None
def get_filter_class(self):
Return the django-filters `FilterSet` used to filter the queryset.
if self.filter_class:
return self.filter_class
if self.filter_fields:
class AutoFilterSet(django_filters.FilterSet):
class Meta:
model = self.model
fields = self.filter_fields
return AutoFilterSet
return None
def filter_queryset(self, queryset):
filter_class = self.get_filter_class()
if filter_class:
return self.filter_class(self.request.GET, queryset=queryset)
return queryset
def get_filtered_queryset(self):
return self.filter_queryset(self.get_queryset())
... # pagination methods as before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.