从管理面板上传django模型中的多个图像

时间:2018-02-24 16:11:16

标签: python django relationship models

我有这个model.py文件但是在django admin我无法上传图片...我如何为每个产品上传多个图片? (1对多关系)

Models.py

TYPE = (('small', 'small'), ('medium', 'medium'), ('big', 'big'))


class Products(models.Model):
    name = models.CharField(max_length=50)
    category = models.CharField(max_length=50, choices=TYPE)
    description = models.TextField()

    def __unicode__(self):
        return self.name


class Gallery(models.Model):
    image_name = models.TextField()
    image_up = models.ImageField(upload_to='prodotti/')
    product = models.ForeignKey(Products)

    def __unicode__(self):
        return self.image_name

0 个答案:

没有答案