#30653: Annotate a whole ORM object with Subquery instead of just a column.
-------------------------------------+-------------------------------------
Reporter: Ivaylo Donchev | Owner: Ivo
| Donchev
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):
* status: assigned => closed
* version: 2.2 => master
* resolution: => wontfix
Comment:
Thanks for this ticket, however you can user
[https://docs.djangoproject.com/en/2.2/ref/models/querysets/#django.db.models.Prefetch
Prefetch()] to prefetch related objects with a custom queryset. I don't
think that a new API is necessary, e.g.:
{{{
>>> qs = Car.objects.prefetch_related(models.Prefetch('owner',
queryset=User.objects.with_annotated_full_name(),
to_attr='annotated_users'))
>>> for car in qs:
... print(car, car.annotated_users.full_name)
Car object (1) a B
Car object (2) e f
....
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30653#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.c88099c58a0fec9dc1ffb14344096634%40djangoproject.com.