I have these models:
class Gallery(models.Model):
HeadImage = models.ImageField(upload_to="gallery")
class Image(models.Model):
Image = models.ImageField(upload_to="gallery")
Gallery = models.ForeignKey(Gallery, related_name='images')
in template i have a gallery object,now I wanna iterate it’s image objects:
{% for i in gallery.image_set.all %}
<td><img src="{{MEDIAL_URL}}{{i.Image.url}}" width="200px" height="200px"/></td>
{% endfor %}
but when I check rendered HTML,I see it doesn’t generate any thing.what’s wrong with it?
tnx in advance
Why do you use gallery.image_set.all? Related name for images in your Gallery model is “images”.