AI AUtomtaion, Schudelign and publishign fromt and backe end refoactr
This commit is contained in:
@@ -839,6 +839,7 @@ class AIModelConfigAdmin(SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
'provider_badge',
|
||||
'credit_display',
|
||||
'quality_tier',
|
||||
'is_testing_icon',
|
||||
'is_active_icon',
|
||||
'is_default_icon',
|
||||
'updated_at',
|
||||
@@ -848,6 +849,7 @@ class AIModelConfigAdmin(SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
'model_type',
|
||||
'provider',
|
||||
'quality_tier',
|
||||
'is_testing',
|
||||
'is_active',
|
||||
'is_default',
|
||||
]
|
||||
@@ -884,7 +886,8 @@ class AIModelConfigAdmin(SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
('Status', {
|
||||
'fields': ('is_active', 'is_default'),
|
||||
'fields': ('is_active', 'is_default', 'is_testing'),
|
||||
'description': 'is_testing: Mark as cheap testing model (one per model_type)'
|
||||
}),
|
||||
('Timestamps', {
|
||||
'fields': ('created_at', 'updated_at'),
|
||||
@@ -969,8 +972,19 @@ class AIModelConfigAdmin(SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
)
|
||||
is_default_icon.short_description = 'Default'
|
||||
|
||||
def is_testing_icon(self, obj):
|
||||
"""Testing status icon - shows ⚡ for testing models"""
|
||||
if obj.is_testing:
|
||||
return format_html(
|
||||
'<span style="color: #f39c12; font-size: 18px;" title="Testing Model (cheap, for testing)">⚡</span>'
|
||||
)
|
||||
return format_html(
|
||||
'<span style="color: #2ecc71; font-size: 14px;" title="Live Model">●</span>'
|
||||
)
|
||||
is_testing_icon.short_description = 'Testing/Live'
|
||||
|
||||
# Admin actions
|
||||
actions = ['bulk_activate', 'bulk_deactivate', 'set_as_default']
|
||||
actions = ['bulk_activate', 'bulk_deactivate', 'set_as_default', 'set_as_testing', 'unset_testing']
|
||||
|
||||
def bulk_activate(self, request, queryset):
|
||||
"""Enable selected models"""
|
||||
@@ -1005,3 +1019,34 @@ class AIModelConfigAdmin(SimpleHistoryAdmin, Igny8ModelAdmin):
|
||||
messages.SUCCESS
|
||||
)
|
||||
set_as_default.short_description = 'Set as default model'
|
||||
|
||||
def set_as_testing(self, request, queryset):
|
||||
"""Set one model as testing model for its type"""
|
||||
if queryset.count() != 1:
|
||||
self.message_user(request, 'Select exactly one model.', messages.ERROR)
|
||||
return
|
||||
|
||||
model = queryset.first()
|
||||
|
||||
# Unset any existing testing model for this type
|
||||
AIModelConfig.objects.filter(
|
||||
model_type=model.model_type,
|
||||
is_testing=True,
|
||||
is_active=True
|
||||
).exclude(pk=model.pk).update(is_testing=False)
|
||||
|
||||
model.is_testing = True
|
||||
model.save()
|
||||
|
||||
self.message_user(
|
||||
request,
|
||||
f'{model.model_name} is now the TESTING {model.get_model_type_display()} model.',
|
||||
messages.SUCCESS
|
||||
)
|
||||
set_as_testing.short_description = 'Set as testing model (cheap, for testing)'
|
||||
|
||||
def unset_testing(self, request, queryset):
|
||||
"""Remove testing flag from selected models"""
|
||||
count = queryset.update(is_testing=False)
|
||||
self.message_user(request, f'{count} model(s) unmarked as testing.', messages.SUCCESS)
|
||||
unset_testing.short_description = 'Unset testing flag'
|
||||
|
||||
Reference in New Issue
Block a user