Quantcast
Channel: Django: Group by foreign key then get max id from group - Stack Overflow
Browsing all 3 articles
Browse latest View live

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 Article



Answer by Francisco for Django: Group by foreign key then get max id from group

Something like:Message.objects.filter(conversation=conversation).latest('id')

View Article

Django: 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
Browsing all 3 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>