def validate_pdf(value):
"""
Validates the uploading file if it is a PDF.
Raises an error if validation not passed.
:param value: The file object.
"""
try:
PyPDF2.PdfFileReader(io.BytesIO(value.read()))
except PyPDF2.utils.PdfReadError:
raise ValidationError('Tried to upload not PDF as a book!')
评论列表
文章目录