feat: Add Global Module Settings and Caption to Images
- Introduced GlobalModuleSettings model for platform-wide module enable/disable settings. - Added 'caption' field to Images model to store image captions. - Updated GenerateImagePromptsFunction to handle new caption structure in prompts. - Enhanced AIPromptViewSet to return global prompt types and validate active prompts. - Modified serializers and views to accommodate new caption field and global settings. - Updated frontend components to display captions and filter prompts based on active types. - Created migrations for GlobalModuleSettings and added caption field to Images.
This commit is contained in:
@@ -9,6 +9,7 @@ class AIPromptSerializer(serializers.ModelSerializer):
|
||||
"""Serializer for AI Prompts"""
|
||||
|
||||
prompt_type_display = serializers.CharField(source='get_prompt_type_display', read_only=True)
|
||||
default_prompt = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = AIPrompt
|
||||
@@ -23,6 +24,18 @@ class AIPromptSerializer(serializers.ModelSerializer):
|
||||
'created_at',
|
||||
]
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'default_prompt']
|
||||
|
||||
def get_default_prompt(self, obj):
|
||||
"""Get live default prompt from GlobalAIPrompt"""
|
||||
from .global_settings_models import GlobalAIPrompt
|
||||
try:
|
||||
global_prompt = GlobalAIPrompt.objects.get(
|
||||
prompt_type=obj.prompt_type,
|
||||
is_active=True
|
||||
)
|
||||
return global_prompt.prompt_value
|
||||
except GlobalAIPrompt.DoesNotExist:
|
||||
return f"ERROR: Global prompt '{obj.prompt_type}' not configured in admin"
|
||||
|
||||
|
||||
class AuthorProfileSerializer(serializers.ModelSerializer):
|
||||
|
||||
Reference in New Issue
Block a user