M
M
maxell2019-09-08 15:37:02
Django
maxell, 2019-09-08 15:37:02

How to store 2 images in the database at once?

I am creating a store on Django, I want to upload a lot of photos to the product card, while the code is like this:
models.py

class Item(models.Model):
    item_title = models.CharField('Название', max_length=200)
    item_description = models.TextField('Описание')
    item_size = models.CharField('Размер', max_length=10)
    item_price = models.IntegerField('Цена')
    item_pub_date = models.DateTimeField('Дата публицкации')
    item_image = models.ImageField('Картинка', upload_to="images", null=True, blank=True,)

Is there a way to upload more than one image?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-09-08
@deepblack

Something like this:

# models.py
class Photo(models.Model):
    offer = models.ForeignKey(Offer, on_delete=models.CASCADE)
    photo = models.ImageField(upload_to=get_image_filename, verbose_name='photo')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question