FieldError when annotating over foreign keys
- by X_9
I have a models file that looks similar to the following:
class WithDate(models.Model):
adddedDate = models.DateTimeField(auto_now_add=True)
modifiedDate = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class Match(WithDate):
...
class Notify(WithDate):
matchId = models.ForeignKey(Match)
headline = models.CharField(null=True, blank=True, max_length=10)
For each Match I'm trying to get a count of notify records that have a headline. So my call looks like
matchObjs = Match.objects.annotate(notifies_made=Count('notify__headline__isnull'))
This keeps throwing a FieldError. I've simplified the query down to
matchObjs = Match.objects.annotate(notifies_made=Count('notify'))
And I still get the same FieldError... I've seen this work in other cases (other documentation, other SO questions like this one) but I can't figure out why I'm getting an error.
The specific error that is returned is as follows:
Cannot resolve keyword 'notify' into field. Choices are: (all fields from Match model)
Does anyone have a clue as to why I can't get this annotation to work across tables? I'm baffled after looking at the other SO question and various Django docs where I've seen this done.
Edit: I am using Django 1.1.1