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

Enhancement: A easier way to filter with exclude=True #1557

Open hongfanmeng opened 1 year ago

hongfanmeng commented 1 year ago
class ExampleFilter(FilterSet):
    id__not__in = NumberInFilter(field_name='id', lookup_expr='in', exclude=True)

is it possible to auto generate [fieldname]__not_\[lookup] filter ?

hongfanmeng commented 1 year ago

To be precise, I want to automatically generate suffix of all lookup with or without exclude

aidanlister commented 1 year ago

I really want this too, https://github.com/carltongibson/django-filter/issues/978 and see this discussion about it, https://github.com/carltongibson/django-filter/discussions/1484

WhiteSage commented 1 year ago

Hello, I have recently started used django-fliters and also stumbled upon this.

I have written some minimal mixins which enable this behavior on django-filters (tested on DRF, not sure if compatible at all with forms). You can find them here https://github.com/WhiteSage/django-filter-autotools .

rodrigondec commented 11 months ago

I invested sometime to analysed and do a extension to have automagically exclude on any lookup. Posted the snnipets here