Answer the question
In order to leave comments, you need to log in
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
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
{{ gallerys.first_photo_url }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question