1👍
✅
You don’t need a custom filter here. Django queryset can follow the reverse relationship very well, for filtering. Check this link: https://docs.djangoproject.com/en/1.8/topics/db/queries/#lookups-that-span-relationships
Here’s how you would modify your get_queryset()
method:
class MentionList(generics.ListAPIView):
def get_queryset(self):
hashtag_filter = self.request.query_params.get('hashtags', None)
return Mention.objects.filter(hashtag__tagname=hashtag_filter)
Source:stackexchange.com