Enhance Content Management with New Taxonomy and Attribute Models

- Introduced `ContentTaxonomy` and `ContentAttribute` models for improved content categorization and attribute management.
- Updated `Content` model to support new fields for content format, cluster role, and external type.
- Refactored serializers and views to accommodate new models, including `ContentTaxonomySerializer` and `ContentAttributeSerializer`.
- Added new API endpoints for managing taxonomies and attributes, enhancing the content management capabilities.
- Updated admin interfaces for `Content`, `ContentTaxonomy`, and `ContentAttribute` to reflect new structures and improve usability.
- Implemented backward compatibility for existing attribute mappings.
- Enhanced filtering and search capabilities in the API for better content retrieval.
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-22 00:21:00 +00:00
parent a82be89d21
commit 55dfd5ad19
17 changed files with 2934 additions and 40 deletions

View File

@@ -7,8 +7,12 @@ from igny8_core.business.planning.models import Clusters, ContentIdeas
from igny8_core.business.content.models import (
ContentClusterMap,
ContentTaxonomyMap,
ContentAttributeMap,
ContentAttribute,
ContentTaxonomy,
ContentTaxonomyRelation,
)
# Backward compatibility
ContentAttributeMap = ContentAttribute
class TasksSerializer(serializers.ModelSerializer):
@@ -351,13 +355,120 @@ class ContentSerializer(serializers.ModelSerializer):
return results
def get_attribute_mappings(self, obj):
mappings = ContentAttributeMap.objects.filter(content=obj)
mappings = ContentAttribute.objects.filter(content=obj)
results = []
for mapping in mappings:
results.append({
'name': mapping.name,
'value': mapping.value,
'attribute_type': mapping.attribute_type,
'source': mapping.source,
'external_id': mapping.external_id,
})
return results
class ContentTaxonomySerializer(serializers.ModelSerializer):
"""Serializer for ContentTaxonomy model"""
parent_name = serializers.SerializerMethodField()
cluster_names = serializers.SerializerMethodField()
content_count = serializers.SerializerMethodField()
class Meta:
model = ContentTaxonomy
fields = [
'id',
'name',
'slug',
'taxonomy_type',
'description',
'parent',
'parent_name',
'external_id',
'external_taxonomy',
'sync_status',
'count',
'metadata',
'cluster_names',
'content_count',
'site_id',
'sector_id',
'account_id',
'created_at',
'updated_at',
]
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id']
def get_parent_name(self, obj):
return obj.parent.name if obj.parent else None
def get_cluster_names(self, obj):
return [cluster.name for cluster in obj.clusters.all()]
def get_content_count(self, obj):
return obj.contents.count()
class ContentAttributeSerializer(serializers.ModelSerializer):
"""Serializer for ContentAttribute model"""
content_title = serializers.SerializerMethodField()
cluster_name = serializers.SerializerMethodField()
class Meta:
model = ContentAttribute
fields = [
'id',
'content',
'content_title',
'cluster',
'cluster_name',
'attribute_type',
'name',
'value',
'external_id',
'external_attribute_name',
'source',
'metadata',
'site_id',
'sector_id',
'account_id',
'created_at',
'updated_at',
]
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id']
def get_content_title(self, obj):
return obj.content.title if obj.content else None
def get_cluster_name(self, obj):
return obj.cluster.name if obj.cluster else None
class ContentTaxonomyRelationSerializer(serializers.ModelSerializer):
"""Serializer for ContentTaxonomyRelation (M2M through model)"""
content_title = serializers.SerializerMethodField()
taxonomy_name = serializers.SerializerMethodField()
taxonomy_type = serializers.SerializerMethodField()
class Meta:
model = ContentTaxonomyRelation
fields = [
'id',
'content',
'content_title',
'taxonomy',
'taxonomy_name',
'taxonomy_type',
'created_at',
]
read_only_fields = ['id', 'created_at']
def get_content_title(self, obj):
return obj.content.title if obj.content else None
def get_taxonomy_name(self, obj):
return obj.taxonomy.name if obj.taxonomy else None
def get_taxonomy_type(self, obj):
return obj.taxonomy.taxonomy_type if obj.taxonomy else None