Saturday, October 25, 2014

How to get related data on one to one field of a foreign key?

That's what you've already done with your select_related call. What you should have asked is how you access that data in the template, and the answer is that you simply follow the relationship from your Log object:

{% for log in logs %}
{{ log.myfield }}
{{ log.userprofile.picture }}
{% endfor %}

--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a1f73c2-03ae-46b6-a9fa-58ef4f4716c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment