Using _set.all in template when ForiegnKey is linked to Self

165 views
Skip to first unread message

Jam

unread,
Mar 22, 2012, 4:12:21 AM3/22/12
to django...@googlegroups.com
Hi All,

I have a model where it can link to itself using ForeignKey('self'). This is so I can have parent and child objects.

I have called the parent and in the template I want to be able to access all the child objects.

I have been using the _set.all template command on the field but it returns no results.

Any ideas why this would happen? This is the first time I have used ForeignKey('self') so I am a bit clueless.

Thank you all
Jamie

Daniel Roseman

unread,
Mar 22, 2012, 5:52:19 PM3/22/12
to django...@googlegroups.com
You'll need to be a bit more specific. Please show your model, and the exact template code you are using. 
--
DR.

Jam

unread,
Mar 23, 2012, 8:22:15 AM3/23/12
to django...@googlegroups.com
I actually managed to find a way to do this.

instead of using {% for fieldname_set.all %} I used {% for RelatedName.all %}

That worked perfectly.
Reply all
Reply to author
Forward
0 new messages