diff --git a/django/db/models/query.py b/django/db/models/query.py
index c8e630a..0cc6c49 100644
a
|
b
|
class QuerySet(object):
|
605 | 605 | Return a query set in which the returned objects have been annotated |
606 | 606 | with data aggregated from related fields. |
607 | 607 | """ |
| 608 | total_aggregates = len(args) + len(kwargs) |
608 | 609 | for arg in args: |
609 | 610 | kwargs[arg.default_alias] = arg |
610 | 611 | |
| 612 | if len(kwargs) != total_aggregates: |
| 613 | raise ValueError("Some of the aggregates had duplicate aliases, " |
| 614 | "check to make sure none of your aggregates conflict with the " |
| 615 | "default aliases.") |
| 616 | |
| 617 | names = set([f.name for f in self.model._meta.fields]) |
| 618 | for aggregate in kwargs: |
| 619 | if aggregate in names: |
| 620 | raise ValueError("The %s aggregate conflicts with a field on " |
| 621 | "the model." % aggregate) |
| 622 | |
| 623 | |
611 | 624 | obj = self._clone() |
612 | 625 | |
613 | 626 | obj._setup_aggregate_query(kwargs.keys()) |
diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index 7c51cd1..ccbbbe7 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 | |