I am using django-rest-framework with https://github.com/alex/django-filter/, but question is mostly about django-filter. I can't understand how to use filters with "__in" lookup.
For example i have model:
class Book(models.Model):
name = models.CharField(max_length=100)
class BookView(viewsets.ReadOnlyModelViewSet):
serializer_class = BookSerializer()
model = Book
filter_fields = ('id', 'name')
And i can't use url like this
/v1/books/?id__in=1,2,3
to find books with id 1, 2 or 3
There's a simple solution with
django_filter
now:And then you can use it in your query string exactly as you wanted:
?id__in=1,2,3
.Customize PKsField and PKsFilter for your id field(AutoField), and then the query params will work: '/v1/books/?id__in=1,2,3'
Hope that can help. Thx.
Not sure if this was ever answered: try: id=[1, 2, 3] for numbers name=["name1", "name2"] for strings