doniyor
doniyor

Reputation: 37846

django for loop over list

i have a list created by zip.

list = zip(rating,image,comment)

all elements are querysets which are iterable.

Image is in this form:

Class image(request):
  location_id = models.IntegerField()
  bild = models.ImageField(upload_to=".",default='')

so, one location can have its multiple images.

now i am rendering that list to template and iterating over it to show the items. Say, one location has 2 Images. my problem is this:

  {% for rate, image, comment in list %}
     how do i show here both images of one location? 
     {{image.bild.name}} gives me only the first image
  {% endfor %}

thanks for help

Upvotes: 1

Views: 263

Answers (1)

user9876
user9876

Reputation: 11102

The Location class should have fields or properties that give you the relevant ratings / comments / images. Then you can just pass a list of Locations to your template.

If Location is a Django model, then the ratings / comments / images should each have a ForeignKey that points to Location. In that case, Django will create properties on Location that point to the corresponding ratings / comments / images. Use related_name to choose the name of that property, otherwise Django will invent a name.

Upvotes: 2

Related Questions