how to filter the inbox messages that belong to a user?

Okay, i am ready

Isn’t there going to be an error with this query, or are we going to do something about it later?


This is the full code up-till now

class MyInbox(generics.ListCreateAPIView):
    serializer_class = MessageSerializer

    def get_queryset(self):
        user_id = self.kwargs['user_id']

        return User.objects.filter(
            Q(sender__receiver=user_id)|Q(receiver__sender=user_id)
            ).distinct().annotate(
            last_msg=Subquery(
                ChatMessage.objects.filter(
                sender__in=[OuterRef('id'), user_id], reciever__in=[OuterRef('id'), user_id]
                )
            ).order_by('-date')[:1].values_list('id',flat=True)
            )