carltongibson / django-filter

A generic system for filtering Django QuerySets based on user selections
https://django-filter.readthedocs.io/en/main/
Other
4.41k stars 766 forks source link

Wouldn't it be nice to have an "extra_kwargs" fields in Meta of FilterSet like DRF ? #1594

Closed ThalusA closed 1 year ago

ThalusA commented 1 year ago

I would love to see something consistent with Django Rest Framework with their extra_kwargs approach. Would you mind adding it to django-filters ? https://www.django-rest-framework.org/api-guide/serializers/#additional-keyword-arguments

It would be nice because it wouldn't make us forced to overwrite the default Filter for a specific field.

carltongibson commented 1 year ago

I don't want to expand the API here. Declare the filters explicitly if needed.

ThalusA commented 1 year ago

How can I keep the configuration for ModelChoiceFilter for null values and everything else using explicit filters then ? Let's imagine you update your default filters for a specific model, how can I fuse default filters with mine so that my filters won't ever get outdated ? @carltongibson

carltongibson commented 1 year ago

See https://django-filter.readthedocs.io/en/main/ref/filterset.html#customise-filter-generation-with-filter-overrides

ThalusA commented 1 year ago

But filter overrides works per field class, not by field name ? What if I have two foreign key and I want custom overrides different for both of them ?