From 863431ef41a56cd97e94964d00886b8d33244287 Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Wed, 13 Sep 2017 22:13:47 -0400 Subject: [PATCH] Added PDF file type restriction --- case_law/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/case_law/models.py b/case_law/models.py index 8d137d6..eecb9fc 100644 --- a/case_law/models.py +++ b/case_law/models.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ValidationError from django.db import models @@ -15,9 +16,13 @@ class Case(models.Model): ('view_pdf', 'Can view PDF'), ) + def validate_file_extension(value): + if not value.name.endswith('.pdf'): + raise ValidationError(u'File is not a PDF') + published = models.DateField() headings = models.ManyToManyField(Heading) - pdf = models.FileField(upload_to='secure') + pdf = models.FileField('PDF', upload_to='secure', validators=[validate_file_extension]) synopsis = models.TextField() def __str__(self):