Tuesday, February 7, 2012

Can prefetch_related() look up reverse relationship?

I'm using django1.4 from svn trunk.
The models are as follows:

class Book(models.Model):
# some stuff

class Price(models.Model):
book = models.ForgeinKey(Book)

Each book can have many prices.

My query in view:
Book.objects.all().prefetch_related('price')

I got this error:
Cannot find 'price' on Book object, 'price' is an invalid parameter to
prefetch_related()

Am I missing something? or prefetch_related cannot handle reverse
lookup.

Thanks in advance.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment