python - How can I retrieve a distinct list of objects for each pair of django users? -
i have private user user messaging model. (photographer foreignkey django user)
class message(models.model): sender = models.foreignkey(photographer) recipient = models.foreignkey(photographer, related_name= 'messagedby', blank=true) posttime = models.datetimefield(auto_now_add=true, null=true, blank =true) message = models.charfield(max_length=500) def __unicode__(self): return self.message
as can see, each message has sender , recipient. both sender , recipient can view same message.
i need retrieve distinct list of latest messages each pair of users.
currently can retrieve distinct pairs returning more results want:
queryset = message.objects.all().distinct('sender', 'recipient')
there multiple messages coming through same pairs of users. example,
john sender , jane recipient.
in returned message,
jane sender , john recipient.
from this, want 1 of these 2 messages latest one. how can accomplish this?
you're looking .distinct()
Comments
Post a Comment