Hi there folks.
I am providing custom query-building by user in my application and am Using django-filter for this.
Dokumentation django-filter
So far, everything is going well and it works according to my needs. But in some cases, I would like to “join” two filter entities. Example code below shows two filter fields. At the moment, i get query-results according to used searchterms, if the searchterm is somewhere within the record.
there can be more than one entry per record for this filter crietria and what i would like to achieve is, that the searchterm of second filter is only filtered if it fits searchterm of first filter in same entry…
examinations__purpose = django_filters.ModelMultipleChoiceFilter(
queryset=Examinations.objects.values_list('purpose', flat=True),
field_name='examinations__purpose',
conjoined=True,
widget=forms.SelectMultiple(attrs={
'class': 'w-100 form-select-sm border border-1 border-black text-center',
}))
examinations__result = django_filters.ModelMultipleChoiceFilter(
queryset=Examinations.objects.values_list('result', flat=True),
field_name='examinations__result',
conjoined=True,
widget=forms.SelectMultiple(attrs={
'class': 'w-100 form-select-sm border border-1 border-black text-center',
}))
class Meta:
model = Employees
fields = [
...
'examinations__purpose', 'examinations__result',
]