Django: Filtering The Distinct Data
I'm trying to build a messaging app. Here's my model, class Message(models.Model): sender = models.ForeignKey(User, related_name='sender') receiver = models.ForeignKey(User
Solution 1:
you can try this code
inbox_message = Message.objects.filter.objects.filter(receiver=request.user).order_by('-created_at')
outbox_message = Message.objects.filter.objects.filter(sender=request.user).order_by('-created_at')
Solution 2:
here thing you need to do,
- fetch sender
request.user
rec - somename fetch receivedMsg for above sender, receiver
request.user
serder - somenamemessage_queue = Message.objects.filter(Q(receiver=rec_name, sender=request.user), Q(receiver=request.user, sender=rec_name).order_by('-created_at')
order by created_at will shuffle like chain
Post a Comment for "Django: Filtering The Distinct Data"