I need to show multiple images uploaded in the Admin page (using FileField) in my html.
I'm currently using:
Python 3.6.0b4
Django 1.10.3
I can currently show if the model only has one image but when I try to put multiple images, I have no idea how to show it.
Here is my code:
models.py
class Product(models.Model):
name = models.CharField(max_length=140)
created_by = models.ForeignKey(User,null=True)
def __str__(self):
return self.name
class ProductImage(models.Model):
name= models.ForeignKey(Product)
image = models.FileField(upload_to='media/',null=True,blank=True)
admin.py
class ProductImageInline(admin.TabularInline):
model = ProductImage
class ProductModelAdmin(admin.ModelAdmin):
exclude = ('created_by',)
inlines = [ProductImageInline]
def save_model(self, request, obj, form, change):
if not change:
obj.created_by = request.user
obj.save()
admin.site.register(Product,ProductModelAdmin)
If I add
image = models.FileField(upload_to='media/',null=True,blank=True)
in my model.py, I can show it in the html like this:
<img width=200 src="{{product.image.url}}" /></a>
How can I show the Multiple Images in the html? I'm fairly new to Django but have experience on web development.
Thanks in advance.