On Mon, 2009-02-02 at 21:37 -0800, Alexiski wrote:
> 
> > On Mon, 2009-02-02 at 21:21 -0800, Alexiski wrote:
> > > Hi Malcolm,
> >
> > > Thanks for your response, but I'm not quite sure how to iterate using
> > > obj.query.all to get all the instances I'm after.
> >
> > > Could you please provide a code snippet or direct me to a relevant
> > > page?
> >
> > Iteration in templates is done with the forloop template tag. You must
> > already be using that to iteratate over all the copy instances.
> 
> Correct I am using the {% for Copy in object_list %} tag. I access the
> fields like so - {{ Copy.id }} {{ Copy.question }}
> 
> In order to access the n Query objects per Copy object, do I nest {%
> for Query in object_list %} and access using {{ Query.id }}
> {{ Query.requirements }} ?

No, because object_list is an sequence of Copy instances, not a sequence
of Query instances. You need to iterate over Copy.query_set.all, using
your variable names, in the nested loop. That is, for each copy instance
loop over the related Query instances.

Note that I probably made a typo earlier, it should be
Copy.query_set.all, not Copy.query.all. In case I've continued to get it
wrong, read the documentation for the queryset API, in particular the
part about accessing reverse relations.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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