Discussion:
Template error "Could not parse the remainder"
Spider
2006-07-12 16:09:22 UTC
Permalink
I have this loop in a template :
{% for s in p.schedule_set.all() %}

The template engine complains with "Could not parse the remainder: ()"

Here p is a Plan object instance. Schedule has Plan as a many-to-one
foreign key (each Plan has 1 or more Schedules).

What I want is to loop through all the Schedules associated with this
Plan. I know that p.schedule_set.all() gives me this, so I guess this
is a limitation of the template parser. Is there a way to achieve what
I want?

I did think of doing the p.schedule_set.all() in my view and passing
the result in, but there problem is that there is a further level of
nesting - each schuled consist of a number of visits, so notionally
what I want is nested loops :
{% for s in p.schedule_set.all() %}
{% for v in s.visit_set.all() %}

I suppose I could pass in nested dictionaries from the view ...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
James Bennett
2006-07-12 16:19:06 UTC
Permalink
Post by Spider
The template engine complains with "Could not parse the remainder: ()"
When doing things like this in a template, you don't use the
parentheses; just {% for s in p.schedule_set.all %}' should work.
Basically, Django tries a few different lookupg methods when it sees
'p.schedule_set.all', and will stop when it finds one that works (in
your case, the manager method). See the documentation for a full
description of how it works:

http://www.djangoproject.com/documentation/templates/#variables
--
"May the forces of evil become confused on the way to your house."
-- George Carlin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
Brett Parker
2006-07-12 16:32:32 UTC
Permalink
Post by Spider
{% for s in p.schedule_set.all() %}
Remove the () and it should be fine
Post by Spider
The template engine complains with "Could not parse the remainder: ()"
Here p is a Plan object instance. Schedule has Plan as a many-to-one
foreign key (each Plan has 1 or more Schedules).
What I want is to loop through all the Schedules associated with this
Plan. I know that p.schedule_set.all() gives me this, so I guess this
is a limitation of the template parser. Is there a way to achieve what
I want?
I did think of doing the p.schedule_set.all() in my view and passing
the result in, but there problem is that there is a further level of
nesting - each schuled consist of a number of visits, so notionally
{% for s in p.schedule_set.all() %}
{% for v in s.visit_set.all() %}
Don't use the ()!

Cheers,
--
Brett Parker

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
Spider
2006-07-12 16:37:56 UTC
Permalink
Thanks to those who replied; removing the () as suggested worked.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Loading...