我正在学习Django入门。通常来讲(从文档角度而言),Imagefield是否用于照片?那么图像文件的哪个字段呢? (例如dmg)。谢谢。
答案 0 :(得分:1)
ImageField
继承了FileField
的所有属性和方法,但也使用Pillow验证了上载的对象是有效的图像。它还有两个附加的可选参数:height_field
和width_field
(每次保存模型实例时,它们分别自动填充图像的高度和宽度)。
示例:
class Photo(models.Model):
image = models.ImageField(blank=True, null=True, upload_to='image_collection', height_field='image_height', width_field='image_width', max_length=1000)
image_height = models.PositiveIntegerField(null=True, blank=True, editable=False)
image_width = models.PositiveIntegerField(null=True, blank=True, editable=False)