List Info

Thread: ManyRelatedManager object is not iterable




ManyRelatedManager object is not iterable
country flaguser name
United States
2007-05-29 20:38:17
With the latest from SVN, I'm getting an error in a
template, but I
can't figure out why...

def obligation_list(request, org_name):
    org = Organization.objects.get(slug=org_name)
    oblig_list = org.obligation_set.all()
    return render_to_response('obligationList.html',
                              {'oblig_list': oblig_list,
'organization':
org},
                              RequestContext(request))

Here's the (relevant part of the) model:

class Obligation(models.Model):
    organization = models.ForeignKey(Organization,
editable=False)

And the (relevant part of the) error I get in the browser:

Template error
In
template
/home/tobryan1/workspace/dmi/src/dmi/orgs/templates/obligati
onList.html, error at line 18


Caught an exception while rendering: 'ManyRelatedManager'
object is not
iterable

18 {% for obligation in oblig_list %}

Any ideas what's going on?

Thanks,
Todd



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: ManyRelatedManager object is not iterable
user name
2007-05-29 20:50:11
On 5/30/07, Todd O'Bryan <toddobryanmac.com> wrote:
>
> Caught an exception while rendering:
'ManyRelatedManager' object is not
> iterable
>
> 18 {% for obligation in oblig_list %}
>
> Any ideas what's going on?

The Manager isn't iterable, but the query sets it produces
are.

You're looking for:

{% for obligation in oblig_list.all %}

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: ManyRelatedManager object is not iterable
country flaguser name
United States
2007-05-29 21:25:33
On Wed, 2007-05-30 at 09:50 +0800, Russell Keith-Magee
wrote:
> On 5/30/07, Todd O'Bryan <toddobryanmac.com> wrote:
> >
> > Caught an exception while rendering:
'ManyRelatedManager' object is not
> > iterable
> >
> > 18 {% for obligation in oblig_list %}
> >
> > Any ideas what's going on?
> 
> The Manager isn't iterable, but the query sets it
produces are.
> 
> You're looking for:
> 
> {% for obligation in oblig_list.all %}
> 
But didn't I already do that in the view? Or am I not
allowed to do
that?

def obligation_list(request, org_name):
    org = Organization.objects.get(slug=org_name)
--> oblig_list = org.obligation_set.all()
    return render_to_response('obligationList.html',
                              {'oblig_list': oblig_list,
'organization':
org},
                              RequestContext(request))

Todd


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


unsubscribe
country flaguser name
United States
2007-05-29 22:25:23
I have been trying to unsubscribe from this list for some
time and it is
not working.
Can the list maintainer please remove me from the list?

On Tue, 2007-05-29 at 21:38 -0400, Todd O'Bryan wrote:
> With the latest from SVN, I'm getting an error in a
template, but I
> can't figure out why...
> 
> def obligation_list(request, org_name):
>     org = Organization.objects.get(slug=org_name)
>     oblig_list = org.obligation_set.all()
>     return render_to_response('obligationList.html',
>                               {'oblig_list':
oblig_list, 'organization':
> org},
>                               RequestContext(request))
> 
> Here's the (relevant part of the) model:
> 
> class Obligation(models.Model):
>     organization = models.ForeignKey(Organization,
editable=False)
> 
> And the (relevant part of the) error I get in the
browser:
> 
> Template error
> In
> template
/home/tobryan1/workspace/dmi/src/dmi/orgs/templates/obligati
onList.html, error at line 18
> 
> 
> Caught an exception while rendering:
'ManyRelatedManager' object is not
> iterable
> 
> 18 {% for obligation in oblig_list %}
> 
> Any ideas what's going on?
> 
> Thanks,
> Todd
> 
> 
> 
> > 
-- 
Mohamed Hussein
http://www.unixgarage.com



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: ManyRelatedManager object is not iterable
country flaguser name
United States
2007-05-30 06:43:52
On Tue, 2007-05-29 at 21:38 -0400, Todd O'Bryan wrote:
> Template error
> In
> template
/home/tobryan1/workspace/dmi/src/dmi/orgs/templates/obligati
onList.html, error at line 18
> 
> 
> Caught an exception while rendering:
'ManyRelatedManager' object is not
> iterable
> 
> 18 {% for obligation in oblig_list %}
> 
OK. I figured out the problem. Russ was right that I had
forgotten
a .all--the problem is that it wasn't here. There was
another for-loop
nested in this one, and that was where the problem was. It's
a mystery
to me why the error was reported with this line instead of
the line
where it actually occurred. Is that maybe a bug?

Todd


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: ManyRelatedManager object is not iterable
user name
2007-05-30 08:42:50
On 5/30/07, Todd O'Bryan <toddobryanmac.com> wrote:
>
> On Tue, 2007-05-29 at 21:38 -0400, Todd O'Bryan wrote:
> > Template error
> > In
> > template
/home/tobryan1/workspace/dmi/src/dmi/orgs/templates/obligati
onList.html, error at line 18
> >
> >
> > Caught an exception while rendering:
'ManyRelatedManager' object is not
> > iterable
> >
> > 18 {% for obligation in oblig_list %}
> >
> OK. I figured out the problem. Russ was right that I
had forgotten
> a .all--the problem is that it wasn't here. There was
another for-loop
> nested in this one, and that was where the problem was.
It's a mystery
> to me why the error was reported with this line instead
of the line
> where it actually occurred. Is that maybe a bug?

Well, yes, if only because the error message made you look
in the
wrong place. If you can provide a specific (cut down)
example where
the template parser produces the wrong line number, it may
be possible
to improve the error message.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )