Allow an annotation to match a field name when using .values on a query set.
|Reported by:||andymckay||Owned by:|
|Component:||Database layer (models, ORM)||Version:||1.3-alpha|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Ticket http://code.djangoproject.com/ticket/11256 has the unfortunate effect of stopping a values query from working.
class Author(models.Model): last_updated = models.DateField() class Book(models.Model): author = models.ForeignKey(Author, related_name='books') pubdate = models.DateField()
authors = Author.objects.values("id").annotate(last_updated=Max('books__pubdate'))
In this case we are using values to only use that one field and last_updated is no longer overriding anything.
Change History (6)
comment:1 Changed 4 years ago by russellm
- Component changed from Uncategorized to ORM aggregation
- milestone set to 1.3
- Needs documentation unset
- Needs tests unset
- Owner nobody deleted
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted