From b59040815fd41ce4d8e6552ca563e205f9a9549c Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Sat, 13 Jan 2024 21:20:09 +0100 Subject: [PATCH] fix: allow passing a filterset class to the filterset factory --- django_filters/filterset.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/django_filters/filterset.py b/django_filters/filterset.py index 1d90db70..6ad099e8 100644 --- a/django_filters/filterset.py +++ b/django_filters/filterset.py @@ -458,9 +458,10 @@ class FilterSet(BaseFilterSet, metaclass=FilterSetMetaclass): pass -def filterset_factory(model, fields=ALL_FIELDS): - meta = type(str("Meta"), (object,), {"model": model, "fields": fields}) - filterset = type( - str("%sFilterSet" % model._meta.object_name), (FilterSet,), {"Meta": meta} +def filterset_factory(model, filterset=FilterSet, fields=ALL_FIELDS): + attrs = {"model": model, "fields": fields} + bases = (filterset.Meta,) if hasattr(filterset, "Meta") else () + Meta = type("Meta", bases, attrs) + return type(filterset)( + str("%sFilterSet" % model._meta.object_name), (filterset,), {"Meta": Meta} ) - return filterset