Skip to content

Commit

Permalink
fix: allow passing a filterset class to the filterset factory
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Jan 19, 2024
1 parent af9f13b commit b590408
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b590408

Please sign in to comment.