Add BackgroundImage model and enhance card templates with dynamic backgrounds
This commit is contained in:
@@ -33,3 +33,29 @@ class Dinosaur(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class BackgroundImage(models.Model):
|
||||
"""Background images used behind card renders.
|
||||
|
||||
Admins can upload multiple backgrounds and mark one as active. Templates
|
||||
will use BackgroundImage.get_active() to obtain the active background.
|
||||
"""
|
||||
title = models.CharField(max_length=200, blank=True)
|
||||
image = models.ImageField(upload_to='backgrounds/')
|
||||
is_active = models.BooleanField(default=False, help_text='Mark as the active background')
|
||||
uploaded_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-is_active', '-uploaded_at']
|
||||
|
||||
def __str__(self):
|
||||
return self.title or f"Background #{self.pk}"
|
||||
|
||||
@classmethod
|
||||
def get_active(cls):
|
||||
"""Return the active BackgroundImage if set, otherwise the most recent one or None."""
|
||||
active = cls.objects.filter(is_active=True).order_by('-uploaded_at').first()
|
||||
if active:
|
||||
return active
|
||||
return cls.objects.order_by('-uploaded_at').first()
|
||||
|
||||
Reference in New Issue
Block a user