diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index 275ea07..35ddf9b 100644
a
|
b
|
class Author(models.Model):
|
15 | 15 | def __unicode__(self): |
16 | 16 | return self.name |
17 | 17 | |
| 18 | class PublisherManager(models.Manager): |
| 19 | use_for_related_fields = True # Line A |
| 20 | def get_query_set(self): |
| 21 | qs = super(PublisherManager, self).get_query_set() |
| 22 | qs = qs.annotate(n_books=models.Count('book')) # Line B |
| 23 | return qs |
| 24 | |
18 | 25 | class Publisher(models.Model): |
19 | 26 | name = models.CharField(max_length=300) |
20 | 27 | num_awards = models.IntegerField() |
21 | 28 | |
| 29 | objects_alternate = PublisherManager() # Line C |
| 30 | objects = models.Manager() # Line D |
| 31 | |
22 | 32 | def __unicode__(self): |
23 | 33 | return self.name |
24 | 34 | |
… |
… |
FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta
|
259 | 269 | >>> Book.objects.annotate(Count('publisher')).values('publisher').count() |
260 | 270 | 6 |
261 | 271 | |
| 272 | # If the default manager adds an annotation and sets use_for_related_fields, saves can fail. |
| 273 | >>> p = Publisher.objects_alternate.all()[0] |
| 274 | >>> p.n_books |
| 275 | 2 |
| 276 | >>> p.save() # Failure. Commenting line A or B or swapping lines C and D, above, will yield success. |
262 | 277 | """ |
263 | 278 | } |
264 | 279 | |