aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/models.py
blob: b11bcb9b70dae31771b2d45e68f0a4bd704f1a32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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"),
]


# 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=AGE_RANGE_CHOICES,
    )
    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",
    )