Say, I have the following two Django models:
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
name = models.CharField(max_length=300)
pages = models.IntegerField()
author = models.ForeignKey(Author)
With django-filter, how can I write a FilterSet, that allows me to filter somewhat like:
Author.objects.filter(
(Q(book__name__contains='How') & Q(book__pages=100)) |
(Q(book__name__contains='Why') & Q(book__pages=50))
)
That is, I want to have a set of filter Fields, that are all applied to a related model and that I can combine. In my case, that set contains many more fields, so a custom MultiValueField is probably not really applicable.
Is there any standard way to solve this using django-filter, or should I implement my own filtering logic in the view?
Qobjects that you want to filter by??book_name_1=How&book_pages_2=100&book_name_2=why&book_pages_2=50