In django, is there a way to directly annotate a query with a related object in single query?

前端 未结 3 547
南旧
南旧 2021-02-05 18:02

Consider this query:

query = Novel.objects.< ...some filtering... >.annotate(
    latest_chapter_id=Max(\"volume__chapter__id\")
)

Actual

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 18:42

    No, it's not possible to combine them into a single query.

    You can read the following blog post to find two workarounds.

提交回复
热议问题