diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-04-08 13:19:48 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-04-08 13:19:48 +0000 |
| commit | 98ef7e85bdaad4b21c31b425a62b2c8bc294be48 (patch) | |
| tree | cde55ff029b2342caec0043500db924c18a05c38 /tests/regressiontests/aggregation_regress | |
| parent | aa9a40b0d8442170cfa3a915c84d6ca687bb93d5 (diff) | |
Fixed #10666 -- Corrected the handling of inherited fields with aggregate() and annotate(). Thanks to julienb for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10446 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/aggregation_regress')
| -rw-r--r-- | tests/regressiontests/aggregation_regress/fixtures/initial_data.json | 14 | ||||
| -rw-r--r-- | tests/regressiontests/aggregation_regress/models.py | 28 |
2 files changed, 39 insertions, 3 deletions
diff --git a/tests/regressiontests/aggregation_regress/fixtures/initial_data.json b/tests/regressiontests/aggregation_regress/fixtures/initial_data.json index 9fb88572b0..597ac041f7 100644 --- a/tests/regressiontests/aggregation_regress/fixtures/initial_data.json +++ b/tests/regressiontests/aggregation_regress/fixtures/initial_data.json @@ -239,5 +239,19 @@ "friends": [8], "name": "Stuart Russell" } + }, + { + "pk": 5, + "model": "aggregation_regress.hardbackbook", + "fields": { + "weight": 4.5 + } + }, + { + "pk": 6, + "model": "aggregation_regress.hardbackbook", + "fields": { + "weight": 3.7 + } } ] diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py index 2dfa1818fc..3ce0f6e75d 100644 --- a/tests/regressiontests/aggregation_regress/models.py +++ b/tests/regressiontests/aggregation_regress/models.py @@ -58,6 +58,12 @@ class Clues(models.Model): EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID') Clue = models.CharField(max_length=150) +class HardbackBook(Book): + weight = models.FloatField() + + def __unicode__(self): + return "%s (hardback): %s" % (self.name, self.weight) + __test__ = {'API_TESTS': """ >>> from django.core import management >>> from django.db.models import get_app, F @@ -137,17 +143,17 @@ __test__ = {'API_TESTS': """ >>> Book.objects.all().aggregate(num_authors=Count('foo')) Traceback (most recent call last): ... -FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, id, isbn, name, pages, price, pubdate, publisher, rating, store +FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store >>> Book.objects.all().annotate(num_authors=Count('foo')) Traceback (most recent call last): ... -FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, id, isbn, name, pages, price, pubdate, publisher, rating, store +FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store >>> Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo')) Traceback (most recent call last): ... -FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, id, isbn, name, pages, price, pubdate, publisher, rating, store, num_authors +FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, contact, hardbackbook, id, isbn, name, pages, price, pubdate, publisher, rating, store, num_authors # Old-style count aggregations can be mixed with new-style >>> Book.objects.annotate(num_authors=Count('authors')).count() @@ -276,6 +282,22 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta >>> publishers [<Publisher: Apress>, <Publisher: Sams>] + + +# Regression for 10666 - inherited fields work with annotations and aggregations +>>> HardbackBook.objects.aggregate(n_pages=Sum('book_ptr__pages')) +{'n_pages': 2078} + +>>> HardbackBook.objects.aggregate(n_pages=Sum('pages')) +{'n_pages': 2078} + +>>> HardbackBook.objects.annotate(n_authors=Count('book_ptr__authors')).values('name','n_authors') +[{'n_authors': 2, 'name': u'Artificial Intelligence: A Modern Approach'}, {'n_authors': 1, 'name': u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'}] + +>>> HardbackBook.objects.annotate(n_authors=Count('authors')).values('name','n_authors') +[{'n_authors': 2, 'name': u'Artificial Intelligence: A Modern Approach'}, {'n_authors': 1, 'name': u'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'}] + + """ } |
