我在Django中创建了一个多图像上传表单,用户可以将个人图像上传到他/她的个人资料中。
我想找/创建一个python函数,将原始图像从用户转换为png
,新的转换图像从我的模型更新png_image
字段。任何想法如何做到这一点?哇,为任何图片上传自动化吗?
models.py
class MyModel(models.Model):
name = models.TextField()
slug_name = models.SlugField()
user = models.ForeignKey(User, unique=False)
original_image = models.ImageField(upload_to=directory_path)
png_image = models.ImageField(upload_to=directory_path)
views.py
def dataset(request):
uploadimages = UploadImagesForm(request.POST or None, request.FILES or None)
if uploadimages.is_valid():
if request.FILES.get('multipleimages', None) is not None:
images = request.FILES.getlist('multipleimages')
for image in images:
...........