나는 모든 s 에서 최신 message
s 각각conversation
을 잡고 싶습니다 . 내 conversation
모델에는 사용자 모델에 대한 외래 키인 속성 id
(기본 키) 및 user1
및 user2
이 있습니다. 내 message
모델은 conversation
(외래 키) 및 메시지 기본 키로 구성됩니다.
둘 다 최신 메시지 만 반환합니다.
Message.objects.values('conversation').latest('id')
Message.objects.order_by('conversation').latest('id')
이 쿼리를 얻기위한 권장 사항이 있습니까?
# get a conversation
conversation = Conversation.objects.first()
# get last created message object in that conversation
last_message = Message.objects.filter(conversation=conversation).last()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다