def clean(self, *args, **kwargs):
data = super(PrivateFileField, self).clean(*args, **kwargs)
file = data.file
if isinstance(file, UploadedFile):
# content_type is only available for uploaded files,
# and not for files which are already stored in the model.
content_type = file.content_type
if self.content_types and content_type not in self.content_types:
logger.debug('Rejected uploaded file type: %s', content_type)
raise ValidationError(self.error_messages['invalid_file_type'])
if self.max_file_size and file.size > self.max_file_size:
raise ValidationError(self.error_messages['file_too_large'].format(
max_size=filesizeformat(self.max_file_size),
size=filesizeformat(file.size)
))
return data
评论列表
文章目录