take a look at my models:
class Gallery(models.Model):
HeadImage = models.ImageField(upload_to="gallery",editable=True,blank=True,null=True)
class Image(models.Model):
Image = models.ImageField(upload_to="gallery")
Gallery = models.ForeignKey(Gallery, related_name='images')
class Tour(Gallery):
Category=models.ForeignKey(TourCategory)
Name=models.CharField(max_length=100)
Count=models.SmallIntegerField()
Now,I have a Tour object that I wanna access to image_set of Tour object,some thing like this:
{% for i in tour.gallery_ptr.images.all %}
<img src="{{MEDIAL_URL}}{{i.Image.url}}" width="500px" height="400px"/>
{% endfor %}
but this doesn’t work,How can I do this?
Trying this in the shell it works fine. Getting all images for a tour object through
tour.gallery_ptr.images.all()will yield all image objects. You might have to perform this operation in your view and not in your template.Additionally, when something fails in a template it fails silently. Trying this in your view you will get the nice big errors telling you exactly what went wrong.