Reputation: 33655
I'm trying to filter a many-to-many feild on a model where I'm give a comma separated list of ids in the URL...
ids = 3,7
cat_ids = self.request.QUERY_PARAMS.get('cat_ids', None)
super(Filter, self).get_queryset(*args,**kwargs).filter(categories__id_in=cat_ids)
Error: TypeError: Related Field got invalid lookup: id_in
Is this possible if so how?
Upvotes: 1
Views: 433
Reputation: 19912
It should be categories__id__in
(double underscore).
See Django documentation: QuerySet API reference.
UPDATE: If with
a comma separated list of ids
you mean a comma separated string of ids, then you should:
cat_ids = self.request.QUERY_PARAMS.get('cat_ids', None).split(',')
Upvotes: 1