You could reference the images from your Product object like so:

product.image_set.all()

You may want to use models.ImageField, which inherits from models.FileField, 
instead of models.FileField


For more information:
https://docs.djangoproject.com/en/1.11/topics/db/examples/many_to_one/
https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.FileField


In your template, you would probably want to use a for loop similar to this:

{% for i in product.image_set.all %}

   <img src=”{{ i.name }}” /><br />

{% endfor %}


From: [email protected] [mailto:[email protected]] On 
Behalf Of [email protected]
Sent: Tuesday, April 25, 2017 4:10 AM
To: Django users
Subject: Displaying the multiple images in the product detail page

I have created a separate image class where you can add images but I'm unable 
to show the multiple images on the product detail page. If anyone can guide me, 
it would be great.


class Image(models.Model):
    active = models.BooleanField(default=True)
    product = models.ForeignKey(Product)
    image = models.FileField(null=True)
    title = models.CharField(max_length=120)

    def __unicode__(self):
        return self.title

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fcff49ff-f999-41eb-a5bb-2abc567c2f73%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fcff49ff-f999-41eb-a5bb-2abc567c2f73%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8eec0f50972547e3b7c0eaa0245eb2d5%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to