Closed Enorio closed 2 years ago
models.EmailField
is mapped separately to models.CharField
(in filtersets.py
) so that's why you're seeing what you are.
Ok. So i just need to add a filter override for the EmailField:
class FooFilter(filters.FilterSet):
class Meta:
model = Foo
fields = ['name', 'invitation_email']
filter_overrides = {
models.CharField: {
'filter_class': filters.CharFilter,
'extra': lambda f: {
'lookup_expr': 'icontains',
},
models.EmailField: {
'filter_class': filters.CharFilter,
'extra': lambda f: {
'lookup_expr': 'icontains',
},
},
},
}
Got it. Thanks :wink:
I'm using the django-filter 21.1.
I have the following model:
What I want is to query Foo using
icontains
, so I've created this class:The problem is that the
lookup_expr
forCharField
is not being changed toicontains
for theinvitation_email
, only for thename
. I've done some debug, and when listing the filters of the FooFilter, it shows this problem.The workaround I found for both to use the
icontains
was this:Am I doing something wrong that I'm not seeing?