IMage genartion service and models revamp - #Migration Runs
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user