I have a custom django filter and I want to get the value of "distance" inside the filter_location function, any ideas how I achieve this?
Reason for wanting to do so, I am doing an external API call to get data and need both the values at the same time.
class ListingFilter(django_filters.FilterSet):
def filter_location(self, queryset, value):
# Want to get the distance filter value here
if value:
#Location value
def filter_distance(self, queryset, value):
pass
distance = django_filters.CharFilter(label='Distance', method=filter_distance)
location = django_filters.CharFilter(label='Location', method=filter_location)
class Meta:
model = Company
fields = ['distance', 'service', 'tags', 'location']
class CompanyListView(viewsets.ReadOnlyModelViewSet):
queryset = Company.objects.all()
filter_class = ListingFilter
everything is in self.data as an ordered dict:
class ListingFilter(django_filters.FilterSet):
def filter_location(self, queryset, value):
print(self.data['distance'])
return queryset