On Sat, Jan 24, 2009 at 2:30 AM, dwil...@gmail.com <dwil...@gmail.com> wrote:
>
> I've got an odd-looking error when I try to use a related model's
> field in the ORM. Here's the traceback:
>
> [...]
>  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')

Try changing that lookup to

collegeyear__year__exact=CURRENT_SEASON

Django has a 'year' lookup for Date (and DateTime?) fields
that in you case is clashing eith the name of one of your field
and is trying to use it, that explains the error you get
(it can't apply it to an integer field).

Hopefully, adding exact will help in disambiguating your
intentions.

>
> And here are the models in question:
>
> class CollegeYear(models.Model):
>    college = models.ForeignKey(College)
>    year = models.IntegerField()
>    wins = models.IntegerField(default=0)


-- 
 Ramiro Morales

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to