aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/models.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-05-14 12:53:28 +0100
committerMatthew Lemon <y@yulqen.org>2024-05-14 12:53:28 +0100
commit46f11648d902b22a177b878e35d6049a7a127ce7 (patch)
treef59f6630717bc9097c988a6d8d3eebe4ad548f1d /pyblackbird_cc/resources/models.py
parentb5e2c4b9a7aab20db6dd6072a01abd114e8e55de (diff)
Can now upload to Spaces
Diffstat (limited to 'pyblackbird_cc/resources/models.py')
-rw-r--r--pyblackbird_cc/resources/models.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 6b20219..68f0637 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -1 +1,105 @@
+from django.db import models
+
+
# 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,
+ related_name="additional_resource_category",
+ )
+ description = models.TextField(max_length=1000, null=False, blank=False)
+ age_range = models.CharField(
+ max_length=20,
+ null=False,
+ default="5-7",
+ blank=False,
+ 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"),
+ ],
+ )
+ curriculum = models.CharField(
+ max_length=20,
+ null=True,
+ 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",
+ )