I'm trying to add filtering capability in a User object ViewSet.
Here's my code:
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
I'd like to be able to filter from the URL - e.g. ./users?username=joe
I've been reading
http://www.django-rest-framework.org/api-guide/filtering/#filtering-against-the-url but that's an example for a ListAPIView, rather than a ModelViewSet, so I get exceptions when I try to add the filtering in.
Obviously, I can do
queryset = User.objects.filter(username='joe')
and it works, but I want to be able to do this from the URL (as well as retain the PK retrieval).
Thanks,
Joe