1👍
✅
You can get the last message like this:
def get_lastmessage(self, obj):
lastmsg = Message.objects.latest('sent_at')
data = {'senderusername': obj.senderusername,
'reciusername': obj.reciusername,
'body': lastmsg.body
'sent_at': lastmsg.sent_at
'last_message': {
'body': lastmsg.body
}
}
return data
Source:stackexchange.com