fields.py 文件源码

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

项目:CSE371Project 作者: muhakh 项目源码 文件源码
def clean(self, *args, **kwargs):
        data = super(ContentTypeRestrictedFileField, self).clean(*args, **kwargs)

        file = data.file
        try:
            content_type = file.content_type
            if content_type in self.content_types:
                if file._size > self.max_upload_size:
                    raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(self.max_upload_size), filesizeformat(file._size)))
            else:
                raise forms.ValidationError(_('Filetype not supported.'))
        except AttributeError:
            pass

        return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号