'How to use Django Filter with Arrayfield
Is it possible to use django-filter BaseInFilter with with django ArrayField?
Here is a sample of what I am trying to do;
models.py
class Stays(models.Model):
best_describes_house = ArrayField(
models.CharField(max_length=500, blank=True, null=True),
default=list,
)
filterset.py
class ItemInFilter(filters.BaseInFilter, filters.CharFilter):
pass
class StayFilter(filters.FilterSet):
best_describes_house__in = ItemInFilter(
field_name="best_describes_house", lookup_expr="in"
)
class Meta:
model = Stays
fields = [
"best_describes_house__in",
]
I am trying to make a request to http://127.0.0.1:8000/api/v1/stays/best_describes_house__in=villa,lake
. I keep getting;
operator does not exist: character varying[] = text[] LINE 1: ...ays" WHERE "lodging_stays"."best_describes_house" IN (ARRAY[...
Am I doing something wrong?
I have also tried doing this using IntegerField
as stated from this example in the documentation - BaseInFilter, and it works fine
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|