I've got an odd-looking error when I try to use a related model's field in the ORM. Here's the traceback:
Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/dwillis/lib/python2.5/django/db/models/query.py", line 519, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/home/dwillis/lib/python2.5/django/db/models/query.py", line 537, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/home/dwillis/lib/python2.5/django/db/models/sql/query.py", line 1375, in add_q can_reuse=used_aliases) File "/home/dwillis/lib/python2.5/django/db/models/sql/query.py", line 1318, in add_filter connector) File "/home/dwillis/lib/python2.5/django/db/models/sql/where.py", line 52, in add obj, params = obj.process(lookup_type, value) File "/home/dwillis/lib/python2.5/django/db/models/sql/where.py", line 255, in process params = self.field.get_db_prep_lookup(lookup_type, value) File "/home/dwillis/lib/python2.5/django/db/models/fields/ related.py", line 157, in get_db_prep_lookup raise TypeError, "Related Field has invalid lookup: %s" % lookup_type TypeError: Related Field has invalid lookup: year It's caused by the following query: active_hc = CollegeCoach.objects.select_related().filter (jobs__name='Head Coach', end_date__isnull=True, collegeyear__year=CURRENT_SEASON).order_by('-start_date') And here are the models in question: class CollegeYear(models.Model): college = models.ForeignKey(College) year = models.IntegerField() wins = models.IntegerField(default=0) losses = models.IntegerField(default=0) ties = models.IntegerField(default=0) ... class CollegeCoach(models.Model): coach = models.ForeignKey(Coach) collegeyear = models.ForeignKey(CollegeYear) jobs = models.ManyToManyField(CoachingJob) start_date = models.DateField() end_date = models.DateField() ... The table mapping to CollegeYear definitely has a year column, and if I change the collegeyear__year to another attribute of CollegeYear, the query works just fine. CURRENT_SEASON is set to an int, which is what that year column is. Any ideas? Derek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---