A
A
Artyom Bryukhanov2015-02-08 12:07:07
Django
Artyom Bryukhanov, 2015-02-08 12:07:07

How to display images in background-image?

How to display images in background-image in style in div class="registryImage" tag?
You need to display the first element photo

{% get_gallerys_list as gallerys_list %}
            {% for gallerys in gallerys_list %}
            <div class="one-third column">
                <div class="registryImage" style="background-image: url({{ gallerys.photo.image.url|first }});">
                {% for photo in gallerys.photo_set.all %}
                    <a class="registryLink" href="{{ photo.image.url }}" rel="prettyPhoto[{{ gallerys.pk }}]" title="{{ photo.title }}">{{ gallerys.title }}</a>
                {% endfor %}   
                </div>
            </div>    
            {% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oscar Django, 2015-02-08
@drupa

class Gallery(models.Model):
    item = models.CharField(max_length=50)

    class Meta:
        verbose_name = u"Галерея"
        verbose_name_plural = u"Галереи"

    def __unicode__(self):
        return self.title

    def first_photo_url(self):
        return self.photo_set.first().image.url

In template:
{{ gallerys.first_photo_url }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question