There is a problem with SearchFilter and JSONFields.
When I add json key to search_fields (json_field__key) I got exception:
django.core.exceptions.FieldDoesNotExist: Model has no field named 'field_name'
Exception comes from SearchFilter class and must_call_distinct method.
I made quick fix by overriding must_call_distinct method but it's not a perfect solution.
class JsonSearchFilter(SearchFilter):
def must_call_distinct(self, queryset, search_fields):
opts = queryset.model._meta
search_fields = [
field
for field in search_fields
if not isinstance(opts.get_field(field.split(LOOKUP_SEP)[0]), JSONField)
]
return super().must_call_distinct(queryset, search_fields)
There is a problem with SearchFilter and JSONFields.
When I add json key to search_fields (json_field__key) I got exception:
django.core.exceptions.FieldDoesNotExist: Model has no field named 'field_name'Exception comes from
SearchFilterclass andmust_call_distinctmethod.I made quick fix by overriding
must_call_distinctmethod but it's not a perfect solution.