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
Source:stackexchange.com