AttributeError with deep Prefetch

21 views
Skip to first unread message

Gagaro

unread,
May 20, 2015, 12:05:01 PM5/20/15
to django...@googlegroups.com
Hello,

I have an issue when trying to using prefetch_related in a queryset
inside a queryset already doing a prefetch_related. I have the
following code:

items = OrderItem.objects.prefetch_related(Prefetch('results'))

orders
= Order.objects.prefetch_related(Prefetch('items', queryset=items))

freights
= Freight.objects.prefetch_related(Prefetch('orders', queryset=orders))

Which results in the following error:
Cannot find 'items' on OrderItem object, 'items__results' is an invalid parameter to prefetch_related()
Models are linked with ForeignKeys (Result => OrderItem => Order => Freight). What am I doing wrong ? Thanks.
Reply all
Reply to author
Forward
0 new messages