Consider this query:
query = Novel.objects.< ...some filtering... >.annotate(
latest_chapter_id=Max("volume__chapter__id")
)
Actually what I need is to annotate each Novel
with its latest Chapter
object, so after this query, I have to execute another query to select actual objects by annotated IDs. IMO this is ugly. Is there a way to combine them into a single query?
distinct()
is useless in this case (correct me if I am wrong), and I don't know any other way to select exactly one chapter except for starting from novel. Any ideas? – Ratsbane