Question: I can't get the image related value when I'm using `{% for %}` with the class Article. I tried with select\_related, but I don't know how to define image to be correctly in displayed in the `src=""` attribute of my `<img />` tag

Is there a clean way to make appear as I want? 

**models.py**

```
    class Image(models.Model):
        gallery = models.ManyToManyField(Gallery)
        name = models.CharField(max_length=100)
        image = models.ImageField(upload_to='static/images/gallery')
        def __str__(self):
            return self.name

    class Article(models.Model):
        section = models.ForeignKey(Menu)
        title = models.CharField(max_length=100)
        text = models.TextField()
        type = models.ForeignKey(Type)
        image = models.ManyToManyField(Image)
        def __str__(self):
            return self.title

```

**views.py**

```
def index(request):
    slider = Article.objects.all()
    images = Image.objects.all()
    return render(request, 'cms/index.html', locals())

```

**template**

```
{% for i in slider %}
<li>
    <img src="{{i.image}}" alt="{{i.title}}"/>
    <h2>{{i.title}}</h2>
    <p>{{i.text}}, {{i.image_url}}</p>
</li>
{% endfor %}

```

Answer: 
You have to use 2 forloop for displaying images in manytomany table.

```
{% for i in slider %}
<li>
    {% for im in i.image.all %}
    <img src="{{im.image.url}}" alt="{{im.name}}"/>
    {% endfor %}
    <h2>{{i.title}}</h2>
    <p>{{i.text}}, {{i.image_url}}</p>
</li>
{% endfor %}

```
`Article.image` is a ManyToMany field. Which image You want to display? First?

```
<img src="{{i.image.all.0.image.url}}" alt="{{i.title}}"/>

```

All?

```
{% for im in i.image.all %}
<img src="{{im.image.url}}" alt="{{im.name}}"/>
{% endfor %}

```