Answer by twrought for Django: Group by foreign key then get max id from group
# get a conversationconversation = Conversation.objects.first()# get last created message object in that conversationlast_message = Message.objects.filter(conversation=conversation).last()
View ArticleAnswer by Francisco for Django: Group by foreign key then get max id from group
Something like:Message.objects.filter(conversation=conversation).latest('id')
View ArticleDjango: Group by foreign key then get max id from group
I'm looking to grab each of the latest messages in all conversations. My conversation model has attributes id (primary key) and user1 and user2, which are both foreign keys to a User model. My message...
View Article
More Pages to Explore .....