0

I am not very familiar with django, but I am hoping someone here will be able to tell me if something is possible.

I am currently calling the latest 4 photo galleries of a set like this:

{% load photogalleries %} 
                {% get_latest_galleries_from_set front-page as photo_gallery limit 4 %}
                {% for gallery in photo_gallery %}
                    <div class="rightSidePairThumb">
                        <a href="{{ gallery.get_first_photo.get_absolute_url }}"><img src="{% mogrify gallery.get_first_photo.get_photo.get_photo_url resize '900x750' filter 'sharpen' %}" alt="{{ gallery.name }}" class="link"/></a>
                        <div class="rightSidePairCat">PHOTOS</div>
                        <div class="coolName"><a href="{{ gallery.get_first_photo.get_absolute_url }}">{{ gallery.name }}</a></div>
                        <hr class="style-two">
                    </div>
                {% endfor %}

I no longer wish to call the 4 latest galleries all at once, but rather get one at a time in different divs on my page. So in one div, I'd like to call the latest gallery. In another div, I'd like to call just the 2nd latest gallery. In another div, just the 3rd latest gallery, etc.

I tried using 'exclude' by id, but I don't know the gallery id's. If anyone knows of a way to accomplish what I am trying to do, I would be eternally grateful.

I can accomplish this using css sibling combinators, (I do it elsewhere on my page) but the code is really long and seems... hacky. I'm hoping there is a much simpler way with django.

Again, I am not very familiar with django, so go easy on the noob.

Thanks in advance!

4

2 に答える 2

0

{% if forloop.counter0 == X %}を使用して現在のループを確認することで、目的を達成できる可能性があります。「ギャラリーIDがわからない」というのが何を意味するのかわかりませんが、{{ gallery.id }}機能しませんか? ともかく..

1 つの可能性:

{% for gallery in galleries %}
    <div class="{% if forloop.first %}latest-gal{% elif forloop.counter0 == 1 %}second-to-latest-gal{% elif forloop.last %}oldest-gal{% else %}third-to-latest-gal{% endif %}">

この ^ はかなり厄介に見えますが。代わりに{{ forloop.counter0 }}、次のように ID で使用することをお勧めします。

{% for gallery in galleries %}
    <div id="gallery-{{ forloop.counter0 }}">

{{ gallery.slug }}通常、私はまたは{{ gallery.id }}をスローし<div id=gallery-"ますが、最新の 4 つのギャラリーのみが必要なようです。そのため、 を使用します{{ forloop.counter0 }}<div id="gallery-0">最新のギャラリーなどに戻ってきます。

于 2013-08-26T21:31:11.043 に答える
0

次のように、リスト内の特定のギャラリーにインデックスでアクセスできます。

{{ photo_gallery.0 }}
{{ photo_gallery.0.get_first_photo.get_absolute_url }}
于 2013-08-26T18:46:41.503 に答える