def save(self, commit=True):
instance = super(InspirationQuoteForm, self).save(commit=True)
if self.cleaned_data["delete_picture"] and instance.picture:
instance.picture.delete()
if self.cleaned_data["picture_path"]:
tmp_path = self.cleaned_data["picture_path"]
abs_tmp_path = os.path.join(settings.MEDIA_ROOT, tmp_path)
filename = InspirationQuote._meta.get_field("picture").upload_to(instance, tmp_path)
instance.picture.save(filename, File(open(abs_tmp_path, "rb")), False)
os.remove(abs_tmp_path)
instance.save()
return instance
forms.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录