IMage genartion service and models revamp - #Migration Runs

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-03 20:08:16 +00:00
parent a70f8cdd01
commit f518e1751b
15 changed files with 817 additions and 287 deletions

View File

@@ -568,10 +568,33 @@ class Images(SoftDeletableModel, SiteSectorBaseModel):
models.Index(fields=['content', 'position']),
models.Index(fields=['task', 'position']),
]
# Ensure unique position per content+image_type combination
constraints = [
models.UniqueConstraint(
fields=['content', 'image_type', 'position'],
name='unique_content_image_type_position',
condition=models.Q(is_deleted=False)
),
]
objects = SoftDeleteManager()
all_objects = models.Manager()
@property
def aspect_ratio(self):
"""
Determine aspect ratio based on position for layout rendering.
Position 0, 2: square (1:1)
Position 1, 3: landscape (16:9 or similar)
Featured: always landscape
"""
if self.image_type == 'featured':
return 'landscape'
elif self.image_type == 'in_article':
# Even positions are square, odd positions are landscape
return 'square' if (self.position or 0) % 2 == 0 else 'landscape'
return 'square' # Default
def save(self, *args, **kwargs):
"""Track image usage when creating new images"""
is_new = self.pk is None