Answer the question
In order to leave comments, you need to log in
How to display a card in a django template?
Good afternoon! I can't figure out how to display the image. My product images are stored in a separate model (so that you can upload several):
class Product(models.Model):
....
class ProductImage(models.Model):
property = models.ForeignKey(Product, related_name='images', null=True)
image = models.ImageField(verbose_name='Image', upload_to=get_image_path)
Answer the question
In order to leave comments, you need to log in
models.py
class Product(models.Model):
@property
def random_pic(self):
return self.images.order_by('?').first()
<img src="{{ product.random_pic.image.url }}">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question