Changes between Initial Version and Version 1 of Ticket #24431
- Timestamp:
- Feb 28, 2015, 1:04:41 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #24431 – Description
initial v1 12 12 13 13 Another Example with some toy models: 14 {{{#!python 14 15 class Address(models.Model): 15 16 city = models.CharField(max_length=40) … … 20 21 data = models.CharField(max_length=40) 21 22 author = models.ForeignKey(Author) 22 23 }}} 23 24 For each author, select a count of their total blog entries, as well as a custom boolean value based on their address: 25 {{{#!python 24 26 Author.objects.all().annotate(blogpost_count=Count('blogpost')).select_related('address').extra(select={'in_maryland':"address.state='MD'"}).count() 25 27 }}} 26 28 This is fine until you append the count() 27 29 … … 30 32 A potential fix is in django/db/models/sql/query.py line 396 in get_aggregation(). 31 33 Change 34 {{{#!python 32 35 inner_query.select_related = False 36 }}} 33 37 To 38 {{{#!python 34 39 if not self._extra: #Skip optimization, extra() fields might need these joins 35 40 inner_query.select_related = False 36 41 }}} 37 42 The cause appears to be a performance optimization (don't do joins if the results don't appear the affect the aggregate). 38 43