Hello!
My model currently looks something like this:
#models.py
class Part(models.Model):
title = models.CharField(max_length=70, unique=True)
category = models.IntegerField(choices=PartTypes.choices(), default=PartTypes.DEFAULT)
pictures = models.CharField(max_length=200)
tags = TaggableManager()
#filters.py
class Tagfilter(filters.CharFilter):
field_class = TagField
def __init__(self, *args, **kwargs):
kwargs.setdefault('lookup_expr', 'in')
super().__init__(*args, **kwargs)
Currently, my Part model supports different categories let's say car, truck, and suv for simplicity.
Each category basically has a field tags (djang-taggit) that allows me to add any tags I want.
I have a UI where the user can filter based on:
First set of filters: (check boxes)
-car
-truck
-suv
Second set of filters: (check-boxes)
-AWD
-4x4
-FWD
-RWD
The expected behavior is that if multiple filters in the same set are checked like (cars, suv) then the request should return cars OR suv only.
However, the issue is when the user selects (cars, suv, and AWD) it currently returns cars OR suv OR AWD. The expected user experience should be like (cars OR suv) AND (AWD).
I am not sure if I need to redo my models.. or I can somehow fix this issue with the way I implement my filters.
Any suggestions?
Thanks!