@@ -163,11 +163,15 @@ def filter(self, qs, value):
163163
164164class FilterSet (filterset .FilterSet ):
165165 """
166- Use this class instead of the :doc:`django-filter <django-filter:index>`
167- :class:`~django_filters.filterset.FilterSet` to automatically set all
168- :class:`~django_enum.fields.EnumField` filters to
169- :class:`~django_enum.filters.EnumFilter` by default instead of
170- :class:`~django_filters.filters.ChoiceFilter`.
166+ This filterset behaves the same way as the :doc:`django-filter <django-filter:index>`
167+ :class:`~django_filters.filterset.FilterSet` except the following fields will be set
168+ to the following filter types:
169+
170+ * :class:`~django_enum.fields.EnumField` -> :class:`~django_enum.filters.EnumFilter`
171+ * :class:`~django_enum.fields.FlagField` -> :class:`~django_enum.filters.FlagFilter`
172+
173+ **If you have a custom** :class:`~django_filters.filterset.FilterSet`
174+ **implementation, this class can also be used as a mixin.**
171175 """
172176
173177 @staticmethod
@@ -178,11 +182,11 @@ def enum_extra(f: EnumField) -> t.Dict[str, t.Any]:
178182 ** {
179183 FlagField : {
180184 "filter_class" : EnumFlagFilter ,
181- "extra" : enum_extra ,
185+ "extra" : lambda f : FilterSet . enum_extra ( f ), # TODO 3.9 compat
182186 },
183187 EnumField : {
184188 "filter_class" : EnumFilter ,
185- "extra" : enum_extra ,
189+ "extra" : lambda f : FilterSet . enum_extra ( f ), # TODO 3.9 compat
186190 },
187191 },
188192 ** filterset .FilterSet .FILTER_DEFAULTS ,
@@ -193,6 +197,8 @@ def filter_for_lookup(
193197 cls , field : ModelField , lookup_type : str
194198 ) -> t .Tuple [t .Optional [t .Type [Filter ]], t .Dict [str , t .Any ]]:
195199 """For EnumFields use the EnumFilter class by default"""
200+ # we can't just pass this up to the base implementation because if it sees
201+ # choices on a field it will hard set to ChoiceField
196202 if isinstance (field , EnumField ):
197203 data = (
198204 try_dbfield (
@@ -209,7 +215,7 @@ def filter_for_lookup(
209215 return (
210216 data ["filter_class" ],
211217 {
212- ** cls .enum_extra (field ),
218+ ** FilterSet .enum_extra (field ),
213219 ** data .get ("extra" , lambda f : {})(field ),
214220 },
215221 )
0 commit comments