I'm on Django 1.7 and have been using the new Prefetch
objects which are a great addition. However I seem to be stuck when I need to traverse back more than one relationship. Here is my code:
product_types = self.get_queryset().select_related().prefetch_related(
'excise_category__exciseitem_set__unit',
Prefetch(
'bevtank_set__package_set__checkout_set',
queryset=CheckOut.objects.filter(
create_date__lte=end_date,
submission__isnull=True,
exempt=False),
to_attr='checkouts_due'
)
)
...
for pt in product_types:
...
co = pt.checkouts_due
...
This gives me a 'ProductType' object has no attribute 'checkouts_due'
on co = pt.checkouts_due
. If I reduce the lookup to a single reverse lookup (for debug purposes) it works okay.
So either there is something wrong with my code, or a limitation on Prefetch. Can anyone shed some light on what might be happening here?
Thanks Nathan