Tuesday, February 7, 2012

Re: Can prefetch_related() look up reverse relationship?

That's awesome, thanks for sharing!

-Jamie

On Tue, Feb 7, 2012 at 7:55 AM, Jonathanz <tianissimo@gmail.com> wrote:
I found it! The correct query shoud be

Book.objects.all().prefetch_related('price_set')


On Feb 7, 5:38 pm, Jonathanz <tianiss...@gmail.com> wrote:
> 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.


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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate