I found solution but very inefficient one:

                                {% with gallery.get_pictureingallery_order as 
ids_in_order %}
                                {% for picture_in_gallery_id in ids_in_order %}
                                {% for picture_in_gallery in
gallery.pictureingallery_set.select_related %}
                                {% ifequal picture_in_gallery_id 
picture_in_gallery.id %}
                                <div class="photo">
                                        {% spaceless %}
                                        <img 
src="{{picture_in_gallery.picture.image.url}}" />
                                        <br />
                                        {% endspaceless %}
                                        <p class="subtitles">
                                        {% for subtitle_id in
picture_in_gallery.get_picturesubtitle_order %}
                                        {% for subtitle in
picture_in_gallery.picturesubtitle_set.select_related %}
                                        {% ifequal subtitle_id subtitle.id %}
                                                {{subtitle}}<br />
                                        {% endifequal %}
                                        {% endfor %}
                                        {% endfor %}
                                        </p>
                                </div>
                                {% endifequal %}
                                {% endfor %}
                                {% endfor %}
                                {% endwith %}

This code makes rendering the template hit database many times.
And things get worse when I have 1-to-many relation nested thrice. Is
there better solution?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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