Skip to content

Commit

Permalink
fix: override default for JSONField field
Browse files Browse the repository at this point in the history
django-filter does not provide a default filter for the JSONField,
therefore we have to provide one for our generic filter
  • Loading branch information
b1rger committed Nov 27, 2023
1 parent 8a28330 commit e3c05f5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apis_core/apis_entities/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import django_filters
from django.conf import settings
from django.db.models import Q
from django.db.models import Q, JSONField

from apis_core.apis_metainfo.models import Collection
from apis_core.apis_entities.models import TempEntityClass
Expand Down Expand Up @@ -63,6 +63,14 @@ class Meta:
# order to load all filters of all model fields by default so that they are available in the first place.
# Later those which are not referenced in the settings file will be removed again
exclude = fields_to_exclude
filter_overrides = {
JSONField: {
"filter_class": django_filters.CharFilter,
"extra": lambda f: {
"lookup_expr": "icontains",
},
}
}

def __init__(self, *args, **kwargs):
# call super init foremost to create dictionary of filters which will be processed further below
Expand Down

0 comments on commit e3c05f5

Please sign in to comment.