diff --git a/django/db/models/query.py b/django/db/models/query.py
index 0d35b0b..63e000d 100644
a
|
b
|
class QuerySet(object):
|
536 | 536 | Return a query set in which the returned objects have been annotated |
537 | 537 | with data aggregated from related fields. |
538 | 538 | """ |
| 539 | total_aggregates = len(args) + len(kwargs) |
539 | 540 | for arg in args: |
540 | 541 | kwargs[arg.default_alias] = arg |
541 | 542 | |
| 543 | if len(kwargs) != total_aggregates: |
| 544 | raise ValueError("Some of the aggregates had duplicate aliases, " |
| 545 | "check to make sure none of your aggregates conflict with the " |
| 546 | "default aliases.") |
| 547 | |
| 548 | names = set([f.name for f in self.model._meta.fields]) |
| 549 | for aggregate in kwargs: |
| 550 | if aggregate in names: |
| 551 | raise ValueError("The %s aggregate conflicts with a field on " |
| 552 | "the model." % aggregate) |
| 553 | |
| 554 | |
542 | 555 | obj = self._clone() |
543 | 556 | |
544 | 557 | obj._setup_aggregate_query(kwargs.keys()) |
diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index 4476b86..857890c 100644
a
|
b
|
Traceback (most recent call last):
|
318 | 318 | ... |
319 | 319 | FieldError: Cannot compute Avg('mean_age'): 'mean_age' is an aggregate |
320 | 320 | |
| 321 | >>> Book.objects.all().annotate(Avg('authors__age'), authors__age__avg=Avg('authors__age')) |
| 322 | Traceback (most recent call last): |
| 323 | ... |
| 324 | ValueError: Some of the aggregates had duplicate aliases, check to make sure none of your aggregates conflict with the default aliases. |
| 325 | |
| 326 | >>> Author.objects.annotate(age=Avg('friends__age')) |
| 327 | Traceback (most recent call last): |
| 328 | ... |
| 329 | ValueError: The age aggregate conflicts with a field on the model. |
| 330 | |
321 | 331 | """ |
322 | 332 | } |
323 | 333 | |