On Jul 3, 2:49 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Jul 3, 7:43 pm, Lee Hinde <[EMAIL PROTECTED]> wrote:
>
>
>
> > Say I have invoices (parent) and payments (child) and I want to show
> > each payment made against the invoices while displaying the list of
> > invoices.
>
> > I've read other discussions here about the problems of automatically
> > loading child records using select_related().
>
> > (http://groups.google.com/group/django-users/browse_frm/thread/
> > 53f30fd617f13f1d/18ecb827406d2b8f?
> > lnk=gst&q=select_related#18ecb827406d2b8f)
>
> > I'm assuming the work around involves a separate query for each
> > Invoice. But I'm not sure how to implement such a thing. (and then
> > reference it in the template.)
>
> > I'm after something that might look like:
>
> > {% for i in  invoice %}
> >    {{i.customer.name}} {{i.invoice.invdate}}
> >         {% for p in  i.payment %}
> >               {{p.paymentdate}} {{p.paymentamount}}
> >         {% endfor %}
>
> > {% endfor %}
>
> > As always, thanks in advance.
>
> >   Lee
> > --
> > The reason I prefer groups to IRC is that in groups, I get to thank
> > you.
>
> You're almost there. The only thing to change is your "for p in..."
> line, which should be:
> {% for p in i.payment_set.all %}
>
> Seehttp://www.djangoproject.com/documentation/db-api/#backwardfor
> the explanation.
> --
> DR.

I ended up using that concept, but in a model method, rather than the
template. I'll add this to the notes.

Thanks very much.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to