This commit is contained in:
alorig
2025-11-22 05:50:07 +05:00
parent c1ce8de9fb
commit 554c1667b3
3 changed files with 144 additions and 4 deletions

View File

@@ -472,3 +472,63 @@ class ContentTaxonomyRelationSerializer(serializers.ModelSerializer):
def get_taxonomy_type(self, obj):
return obj.taxonomy.taxonomy_type if obj.taxonomy else None
class UpdatedTasksSerializer(serializers.ModelSerializer):
"""Updated Serializer for Tasks model with new fields."""
cluster_name = serializers.SerializerMethodField()
sector_name = serializers.SerializerMethodField()
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_taxonomies = serializers.SerializerMethodField()
content_attributes = serializers.SerializerMethodField()
class Meta:
model = Tasks
fields = [
'id',
'title',
'description',
'keywords',
'cluster_id',
'cluster_name',
'sector_name',
'idea_id',
'idea_title',
'content_structure',
'content_type',
'status',
'content',
'word_count',
'meta_title',
'meta_description',
'content_html',
'content_primary_keyword',
'content_secondary_keywords',
'content_taxonomies',
'content_attributes',
'assigned_post_id',
'post_url',
'created_at',
'updated_at',
'site_id',
'sector_id',
'account_id',
]
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id']
def get_content_taxonomies(self, obj):
"""Fetch related taxonomies."""
return ContentTaxonomyRelationSerializer(
obj.content.taxonomies.all(), many=True
).data
def get_content_attributes(self, obj):
"""Fetch related attributes."""
return ContentAttributeSerializer(
obj.content.attributes.all(), many=True
).data

View File

@@ -0,0 +1,48 @@
from django.db import migrations
def migrate_legacy_fields(apps, schema_editor):
Content = apps.get_model('igny8_core', 'Content')
Task = apps.get_model('igny8_core', 'Task')
# Migrate legacy fields in Content model
for content in Content.objects.all():
if content.categories:
# Convert JSON categories to ContentTaxonomy
categories = content.categories
for category in categories:
taxonomy, created = ContentTaxonomy.objects.get_or_create(
name=category['name'],
slug=category['slug'],
taxonomy_type='category'
)
content.taxonomies.add(taxonomy)
if content.tags:
# Convert JSON tags to ContentTaxonomy
tags = content.tags
for tag in tags:
taxonomy, created = ContentTaxonomy.objects.get_or_create(
name=tag['name'],
slug=tag['slug'],
taxonomy_type='tag'
)
content.taxonomies.add(taxonomy)
content.save()
# Migrate legacy fields in Task model
for task in Task.objects.all():
task.entity_type = task.content.entity_type
task.cluster_role = task.content.cluster_role
task.cluster_id = task.content.cluster_id
task.save()
class Migration(migrations.Migration):
dependencies = [
('igny8_core', '0005_phase3_mark_deprecated_fields'),
]
operations = [
migrations.RunPython(migrate_legacy_fields),
]