{{{
m = Message.objects.annotate(room__something=Value('DOH',
output_field=CharField())).select_related('room')
m.room.something == 'DOH' # is true
}}}
Perhaps the annotate API should accept a kwarg -
{{{
m = Message.objects.annotate(room__something=Value('DOH',
output_field=CharField()), annotate_related=True).select_related('room')
m.room.something == 'DOH' # is true
}}}
https://stackoverflow.com/questions/69771898/is-there-a-way-to-annotate-a
-related-field-in-django
--
Ticket URL: <https://code.djangoproject.com/ticket/33242>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => wontfix
Comment:
Thanks for the proposition. `QuerySet.annotate()`annotates each object in
the `QuerySet` with the expression, so you can use
`.annotate(room_something=...)` and refer it in the main object. IMO
adding support for annotating related-objects would make the API
unnecessarily complicated without any clear benefits.
You can raise the idea on the DevelopersMailingList to reach a wider
audience and see what other think.
--
Ticket URL: <https://code.djangoproject.com/ticket/33242#comment:1>