from django.db import models CURRICULUM_CHOICES = [ ("No curriculum", "No curriculum"), ("English", "English"), ("Scottish", "Scottish"), ] AGE_RANGE_CHOICES = [ ("3-5", "3-5"), ("5-7", "5-7"), ("7-11", "7-11"), ("11-14", "11-14"), ("14-16", "14-16"), ("16+", "16+"), ("Age not applicable", "Age not applicable"), ] DESC_HELP_TEXT = """ Markdown acceptable here!This is your opportunity to clearly explain what your resource is all about! It’s worth remembering that you are using the space to communicate to two different audiences. Firstly, think about what fellow teachers would like to know, such as exactly what the resource contains and how it could be used in the classroom. Secondly, the words you include on this page are also talking to internal and external search engines. External search engines, like Google, show the first 155 characters of the resource description, so make sure you take advantage of these characters by using lots of relevant keywords as part of an enticing pitch. """ # Create your models here. class Resource(models.Model): name = models.CharField(max_length=255, null=False) thumbnail_filenames = models.JSONField( null=False, verbose_name="Thumbnail filenames", default=list, ) resource_type = models.ForeignKey("ResourceType", on_delete=models.CASCADE) main_resource_category = models.ForeignKey( "ResourceCategory", on_delete=models.CASCADE, null=False, related_name="main_resource_category", ) additional_resource_category = models.ForeignKey( "ResourceCategory", on_delete=models.CASCADE, null=True, blank=True, related_name="additional_resource_category", ) description = models.TextField( max_length=5000, null=False, blank=False, help_text=DESC_HELP_TEXT, ) age_range = models.CharField( max_length=20, null=False, default="5-7", blank=False, choices=AGE_RANGE_CHOICES, ) curriculum = models.CharField( max_length=20, default="English", blank=True, choices=[ ("No curriculum", "No curriculum"), ("English", "English"), ("Scottish", "Scottish"), ], ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.name class ResourceType(models.Model): name = models.CharField(max_length=255, null=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.name class ResourceCategory(models.Model): name = models.CharField(max_length=255, null=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: verbose_name_plural = "Resource Categories" def __str__(self): return self.name class PDFResource(models.Model): resource = models.ForeignKey( "Resource", on_delete=models.CASCADE, null=False, related_name="pdf_resources", ) file_name = models.CharField(max_length=255, null=False) file_size = models.IntegerField(null=False) class Meta: unique_together = ("resource", "file_name") def snapshot_file_names(self): return [f.file_name for f in self.pdf_page_snapshots.all()] class PDFPageSnapshot(models.Model): name = models.CharField(max_length=255, null=False) file_name = models.CharField(max_length=255, null=False) pdf_file = models.ForeignKey( "PDFResource", on_delete=models.CASCADE, null=False, related_name="pdf_page_snapshots", )