On Sunday, 11 September 2011 08:23:16 UTC+1, Petey wrote:
>
> The more time I spend with django, the more problems pop up :)
>
> I dont fully understand how to access related fields between models. (FK or 
> ManyToMany)
> Code:
> http://pastebin.com/qbciYqYw
>
> In code pasted below - {{p.souce.all}} returns source name but in that 
> form:  [<Source: Google >], instead of "Google".
> Also I dont know how to access source.url.
>
>    1. {% for p in publisher.object_list %}
>    2.         {{ p.date_added|date:"d-m-Y" }} r.
>    3.         {{ p.source.all }}
>    4. <br> 
>    5. {{ p.type|title }}  
>    6. {% endfor %}
>    7. 
>    
> Could you explain me how does that work? I couldn't figure it out only by 
> documentation, I need some examples :)
>
>
It should be obvious that `p.source.all` returns *all* the related `source` 
objects - so it returns a Queryset, which is iterable. If you want to access 
the first item in the list, then you can slice it, like any other list. 
Because of the special syntax restrictions in templates, you can do 
`p.source.all.0` (rather than `p.source.all()[0]` which is what you would do 
in Python code).
--
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/-/YHk8pLktsO0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to