From d421e56e0924487861e6cf5300f462c9e66fd376 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sun, 26 May 2024 20:47:03 +0100 Subject: Correctly handles the unique constraint on feature_slot --- pyblackbird_cc/resources/models.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'pyblackbird_cc/resources/models.py') diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py index 0d1bbe3..33fd678 100644 --- a/pyblackbird_cc/resources/models.py +++ b/pyblackbird_cc/resources/models.py @@ -60,7 +60,8 @@ class Resource(models.Model): max_length=1000, blank=True, default="", - help_text="If you enter text here, it will be used in the 'card' description box on the home page. Max 1000 characters.", + help_text=("If you enter text here, it will be used in the 'card' " + "description box on the home page. Max 1000 characters."), ) age_range = models.CharField( max_length=20, @@ -80,7 +81,7 @@ class Resource(models.Model): ], ) feature_slot = models.IntegerField( - choices=((0, 0), (1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True, default=0, + choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True, blank=True, default=0, ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) @@ -94,8 +95,7 @@ class Resource(models.Model): def get_pdf_snapshot_file_names(self): rs = self.pdf_resources.all() sh = [sh for sh in rs.values_list("pdf_page_snapshots__file_name", flat=True)] - out = [s for s in sh if s] - return out + return [s for s in sh if s] class ResourceType(models.Model): @@ -151,17 +151,3 @@ class PDFPageSnapshot(models.Model): def __str__(self): return self.name - - -# class FeatureResource(models.Model): -# resource = models.ForeignKey( -# "Resource", -# on_delete=models.CASCADE, -# null=False, -# related_name="feature_resources", -# ) -# slot = models.IntegerField(null=False, choices=[(1, 1), (2, 2), (3, 3)]) -# description = models.CharField(max_length=255, null=False) -# -# def __str__(self): -# return f"{self.resource.name} as a feature in slot {self.slot}" -- cgit v1.2.3