I have a model 'Product' to upload products.
class Product(BaseModel):
...
...
class Meta:
db_table = TABLE_PREFIX + "product"
I have another table with product as foreignkey.
class ProductImage(BaseModel):
product = models.ForeignKey(Product, on_delete=models.CASCADE, null=True, blank=True)
image = models.ImageField(upload_to='product')
class Meta:
db_table = TABLE_PREFIX + "product_image"
In home page i want to display these products. I have the home view as
def home(request):
category_obj = Category.objects.all()
product_obj = Product.objects.all().order_by('-id')
context = {
"title": "Home",
"product_obj": product_obj,
"category_obj": category_obj,
}
return render(request, "home/index.html", context)
In the template I want to display the products along with the images.
I am able to display all the details in the template except images.
<div class="dFlex product-list-wrap">
{% for product in product_obj %}
<div class="img-wrap">
<img src="" alt="Product Image">
</div>
<h4>{{ product.name}}</h4>
<p>{{ product.description}}</p>
{% endfor %}
</div>
How do i display images on my template? How can I query images also while querying products?
Thank you