Quantcast

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

classic Classic list List threaded Threaded
3 messages Options
Jam
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Jam
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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/YYk3NpVjDrkJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Daniel Roseman-2
On Thursday, 22 March 2012 01:12:21 UTC-7, Jam wrote:
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

You'll need to be a bit more specific. Please show your model, and the exact template code you are using. 
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/484iTAEhTToJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Jam
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Jam
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.

On Thursday, March 22, 2012 11:52:19 PM UTC+2, Daniel Roseman wrote:
On Thursday, 22 March 2012 01:12:21 UTC-7, Jam wrote:
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

You'll need to be a bit more specific. Please show your model, and the exact template code you are using. 
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/aud_H6IwckMJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Loading...