0

I am making a Django Chat app and I try to create an all message window, where I need all of the last messages that I got from the users

I already tried distinct() and with .values() but nothing worked(I know I miss spelled recenpen_id, that is not the problem)

class MessageView(APIView):
    def get(self, request):

        message = Message.objects.order_by().filter(recepien_id=request.user.id)
        serializer = MessagesSerializer(message, many=True)
        return Response({"message_info":serializer.data})
mrkkrly
  • 35
  • 3
  • Possible duplicate of [Django Query That Get Most Recent Objects From Different Categories](https://stackoverflow.com/questions/2074514/django-query-that-get-most-recent-objects-from-different-categories) – Mehak Jul 04 '19 at 17:25
  • Message.objects.filter(recepien_id=request.user.id).order_by('-id') or you can write meta in your model like this : class Meta: ordering = ['-id','recepien_id'] – hassanzadeh.sd Jul 04 '19 at 19:47

0 Answers0