Created
February 15, 2023 11:15
-
-
Save Tobi-De/cb97d668620d7d5e1a3ca08051188007 to your computer and use it in GitHub Desktop.
filter in multiple fields with django-filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationFilter(django_filters.FilterSet): | |
q = django_filters.CharFilter(method='my_custom_filter', label="Search") | |
class Meta: | |
model = Location | |
fields = ['q'] | |
def my_custom_filter(self, queryset, name, value): | |
return queryset.filter( | |
Q(loc__icontains=value) | | |
Q(loc_mansioned__icontains=value) | | |
Q(loc_country__icontains=value) | | |
Q(loc_modern__icontains=value) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment