26๐
โ
I donโt believe this way will work. When you pass the value in querystring, I guess Django will recieve as a string.
โ EDIT โ
The above answer wont work is need to add more years, I got the solution 127.0.0.1:8000/blogs?years=2018&years=2019
and
years = self.request.query_params.getlist('years', '')
converts this to list.
โ @indavinci
๐คThiago Schettini
6๐
I think a better a better and cleaner way to solve this problem is to just pass the string as comma-separated values in query params and split them up in your Django View.
URL:
http://127.0.0.1:8000/blogs?years=2018,2019
Your View:
def get_queryset(self):
years = self.request.query_params.get('years').split(',')
return self.queryset.filter(year__in=years)
๐คIshant Dahiya
- How can I use OrderingFilter without exposing the names of the fields in the database
- Is it possible to disable django related_name for a specific field?
Source:stackexchange.com