In my viewSet I am doing a query,
queryset= Books.objects.all();
Now from an ajax call I get my filter values from UI i.e. age,gender, etc. of
Maybe django-filter would help simplify the solutions others have given?
Something like:
class BookFilter(django_filters.FilterSet):
class Meta:
model = Book
fields = ['author__age', 'author__gender', ...]
Then the view looks like:
def book_list(request):
f = BookFilter(request.GET, queryset=Book.objects.all())
return render_to_response('my_app/template.html', {'filter': f})
For more information see the documentation.