fixed usage limits of used
This commit is contained in:
@@ -459,8 +459,10 @@ class Images(SoftDeletableModel, SiteSectorBaseModel):
|
||||
all_objects = models.Manager()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""Automatically set account, site, and sector from content or task"""
|
||||
# Prefer content over task
|
||||
"""Track image usage when creating new images"""
|
||||
is_new = self.pk is None
|
||||
|
||||
# Automatically set account, site, and sector from content or task
|
||||
if self.content:
|
||||
self.account = self.content.account
|
||||
self.site = self.content.site
|
||||
@@ -469,7 +471,44 @@ class Images(SoftDeletableModel, SiteSectorBaseModel):
|
||||
self.account = self.task.account
|
||||
self.site = self.task.site
|
||||
self.sector = self.task.sector
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# Increment usage for new images
|
||||
if is_new:
|
||||
from igny8_core.business.billing.services.limit_service import LimitService
|
||||
try:
|
||||
account = self.account
|
||||
if account:
|
||||
# Track image prompt usage
|
||||
if self.prompt:
|
||||
LimitService.increment_usage(
|
||||
account=account,
|
||||
limit_type='image_prompts',
|
||||
amount=1,
|
||||
metadata={
|
||||
'image_id': self.id,
|
||||
'image_type': self.image_type,
|
||||
'content_id': self.content.id if self.content else None,
|
||||
}
|
||||
)
|
||||
|
||||
# Track basic image usage (for now, all images are counted as basic)
|
||||
# TODO: Implement premium image tracking when premium models are used
|
||||
LimitService.increment_usage(
|
||||
account=account,
|
||||
limit_type='images_basic',
|
||||
amount=1,
|
||||
metadata={
|
||||
'image_id': self.id,
|
||||
'image_type': self.image_type,
|
||||
'content_id': self.content.id if self.content else None,
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.error(f"Error incrementing image usage for image {self.id}: {str(e)}")
|
||||
|
||||
def __str__(self):
|
||||
content_title = self.content.title if self.content else None
|
||||
|
||||
Reference in New Issue
Block a user