forms.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Django-Web-Development-with-Python 作者: PacktPublishing 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号