[Fixed]-Filter queryset with one of two criteria that match with the user. Django Rest Framework

1👍

You need to define a get_queryset method on the viewset rather than the queryset field.

You can then access the request object to access the current user.

def get_queryset(self):
    return Message.objects.filter(Q(recipient=self.request.user) | Q(sender=self.request.user))

You can find another example in the docs for ModelViewSet

👤Sayse

Leave a comment