Trying to understand how django_filters works, I played around with one of the test examples like this:
class BookFilter(django_filters.FilterSet):
title = django_filters.CharFilter(lookup_type='contains')
price = django_filters.NumberFilter(lookup_type='lte')
average_rating = django_filters.NumberFilter(lookup_type='gte')
class Meta:
model = Book
fields = ['title', 'price', 'average_rating']
So Filter.__init__ goes through the BookFilter twice for each of these fields.
The first time, the name is None and the lookup_type is as-specified (e.g. 'contains', 'lte', etc.).
The second time the name is the field name as listed in Meta.fields and the lookup_type is the default, 'exact'. The second time is what counts and is used.
I tried a bunch of variations, putting the name in the filter def, putting the lookup_types in __init__, nothing worked. The lookup_types all ended up being 'exact'.
What am I doing wrong?
Thanks,
Bob Haugen