Skip to content

Commit

Permalink
feat(banner_config): make BannerConfig fields nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
elisa-a-v committed Dec 6, 2024
1 parent 442d237 commit ecab98c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.1.1 on 2024-12-06 16:59

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="bannerconfig",
name="banner_button_link",
field=models.URLField(blank=True, null=True),
),
migrations.AlterField(
model_name="bannerconfig",
name="banner_button_text",
field=models.CharField(blank=True, max_length=40, null=True),
),
migrations.AlterField(
model_name="bannerconfig",
name="banner_text",
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name="bannerconfig",
name="banner_title",
field=models.CharField(blank=True, max_length=255, null=True),
),
]
11 changes: 6 additions & 5 deletions bc/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class BannerConfig(models.Model):
default=False,
help_text="If another config is currently active, enabling this one will deactivate the first one.",
)
banner_title = models.CharField(max_length=255)
banner_text = models.TextField()
banner_button_text = models.CharField(max_length=40)
banner_button_link = models.URLField()
banner_title = models.CharField(max_length=255, null=True, blank=True)
banner_text = models.TextField(null=True, blank=True)
banner_button_text = models.CharField(max_length=40, null=True, blank=True)
banner_button_link = models.URLField(null=True, blank=True)

class Meta:
# This constraint ensures that only one BannerConfig
Expand All @@ -45,7 +45,8 @@ class Meta:

def __str__(self):
status = "active" if self.is_active else "inactive"
return f"{self.pk}: {self.banner_title} ({status})"
title = self.banner_title or "Banner"
return f"{self.pk}: {title} ({status})"

def save(self, *args, **kwargs):
# If this banner is being activated, deactivate others.
Expand Down

0 comments on commit ecab98c

Please sign in to comment.