Refactor content handling in GenerateContentFunction and update related models and serializers

- Enhanced GenerateContentFunction to save content in a dedicated Content model, separating it from the Tasks model.
- Updated Tasks model to remove SEO-related fields, now managed in the Content model.
- Modified TasksSerializer to include new content fields and adjusted the API to reflect these changes.
- Improved the auto_generate_content_task method to utilize the new save_output method for better content management.
- Updated frontend components to display new content structure and metadata effectively.
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-10 14:06:15 +00:00
parent 8bb4c5d016
commit 8b6e18649c
11 changed files with 596 additions and 356 deletions

View File

@@ -10,6 +10,11 @@ class TasksSerializer(serializers.ModelSerializer):
idea_title = serializers.SerializerMethodField()
site_id = serializers.IntegerField(write_only=True, required=False)
sector_id = serializers.IntegerField(write_only=True, required=False)
content_html = serializers.SerializerMethodField()
content_primary_keyword = serializers.SerializerMethodField()
content_secondary_keywords = serializers.SerializerMethodField()
content_tags = serializers.SerializerMethodField()
content_categories = serializers.SerializerMethodField()
class Meta:
model = Tasks
@@ -30,10 +35,11 @@ class TasksSerializer(serializers.ModelSerializer):
'word_count',
'meta_title',
'meta_description',
'primary_keyword',
'secondary_keywords',
'tags',
'categories',
'content_html',
'content_primary_keyword',
'content_secondary_keywords',
'content_tags',
'content_categories',
'assigned_post_id',
'post_url',
'created_at',
@@ -75,6 +81,32 @@ class TasksSerializer(serializers.ModelSerializer):
return None
return None
def _get_content_record(self, obj):
try:
return obj.content_record
except AttributeError:
return None
def get_content_html(self, obj):
record = self._get_content_record(obj)
return record.html_content if record else None
def get_content_primary_keyword(self, obj):
record = self._get_content_record(obj)
return record.primary_keyword if record else None
def get_content_secondary_keywords(self, obj):
record = self._get_content_record(obj)
return record.secondary_keywords if record else []
def get_content_tags(self, obj):
record = self._get_content_record(obj)
return record.tags if record else []
def get_content_categories(self, obj):
record = self._get_content_record(obj)
return record.categories if record else []
class ImagesSerializer(serializers.ModelSerializer):
"""Serializer for Images model"""
@@ -122,6 +154,14 @@ class ContentSerializer(serializers.ModelSerializer):
'html_content',
'word_count',
'metadata',
'title',
'meta_title',
'meta_description',
'primary_keyword',
'secondary_keywords',
'tags',
'categories',
'status',
'generated_at',
'updated_at',
'account_id',