oacpl/case_law/models.py

30 lines
736 B
Python
Raw Normal View History

2017-09-13 22:13:47 -04:00
from django.core.exceptions import ValidationError
2017-09-05 02:24:11 -04:00
from django.db import models
2017-09-06 00:28:39 -04:00
class Heading(models.Model):
2017-09-05 02:24:11 -04:00
name = models.CharField(max_length=100)
def __str__(self):
return self.name
2017-09-06 00:28:39 -04:00
class Case(models.Model):
class Meta(object):
permissions = (
('view_pdf', 'Can view PDF'),
)
2017-09-13 22:13:47 -04:00
def validate_file_extension(value):
if not value.name.endswith('.pdf'):
raise ValidationError(u'File is not a PDF')
2017-09-06 00:28:39 -04:00
published = models.DateField()
headings = models.ManyToManyField(Heading)
2017-09-13 22:13:47 -04:00
pdf = models.FileField('PDF', upload_to='secure', validators=[validate_file_extension])
2017-09-05 02:24:11 -04:00
synopsis = models.TextField()
def __str__(self):
return self.synopsis