backedn
This commit is contained in:
@@ -6,23 +6,25 @@ from igny8_core.business.content.models import ContentTaxonomy, ContentAttribute
|
||||
|
||||
@admin.register(Tasks)
|
||||
class TasksAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
list_display = ['title', 'site', 'sector', 'status', 'cluster', 'created_at']
|
||||
list_filter = ['status', 'site', 'sector', 'cluster']
|
||||
list_display = ['title', 'entity_type', 'cluster_role', 'site', 'sector', 'status', 'cluster', 'created_at']
|
||||
list_filter = ['status', 'entity_type', 'cluster_role', 'site', 'sector', 'cluster']
|
||||
search_fields = ['title', 'description', 'keywords']
|
||||
ordering = ['-created_at']
|
||||
readonly_fields = ['content_type', 'content_structure', 'entity_type', 'cluster_role', 'assigned_post_id', 'post_url']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
'fields': ('title', 'description', 'status', 'site', 'sector')
|
||||
}),
|
||||
('Content Classification', {
|
||||
'fields': ('entity_type', 'cluster_role', 'taxonomy')
|
||||
}),
|
||||
('Planning', {
|
||||
'fields': ('cluster', 'idea', 'keywords')
|
||||
}),
|
||||
('Deprecated Fields (Read-Only)', {
|
||||
'fields': ('content_type', 'content_structure', 'entity_type', 'cluster_role', 'assigned_post_id', 'post_url'),
|
||||
'classes': ('collapse',),
|
||||
'description': 'These fields are deprecated. Use Content model instead.'
|
||||
('Timestamps', {
|
||||
'fields': ('created_at', 'updated_at'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -88,7 +90,7 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
list_filter = ['entity_type', 'content_format', 'cluster_role', 'source', 'sync_status', 'status', 'site', 'sector', 'generated_at']
|
||||
search_fields = ['title', 'meta_title', 'primary_keyword', 'task__title', 'external_url']
|
||||
ordering = ['-generated_at']
|
||||
readonly_fields = ['categories', 'tags']
|
||||
readonly_fields = ['generated_at', 'updated_at']
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
@@ -111,10 +113,9 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
'fields': ('linker_version', 'optimizer_version', 'optimization_scores', 'internal_links'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
('Deprecated Fields (Read-Only)', {
|
||||
'fields': ('categories', 'tags'),
|
||||
'classes': ('collapse',),
|
||||
'description': 'These fields are deprecated. Use taxonomies M2M instead.'
|
||||
('Timestamps', {
|
||||
'fields': ('generated_at', 'updated_at'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# Generated migration to clean up deprecated fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_deprecated_data(apps, schema_editor):
|
||||
"""Migrate data from deprecated fields to new unified structure"""
|
||||
Tasks = apps.get_model('writer', 'Tasks')
|
||||
Content = apps.get_model('writer', 'Content')
|
||||
|
||||
# Migrate Tasks: ensure entity_type and cluster_role have defaults
|
||||
for task in Tasks.objects.all():
|
||||
changed = False
|
||||
if not task.entity_type:
|
||||
task.entity_type = 'post'
|
||||
changed = True
|
||||
if not task.cluster_role:
|
||||
task.cluster_role = 'hub'
|
||||
changed = True
|
||||
if changed:
|
||||
task.save()
|
||||
|
||||
# Migrate Content: ensure entity_type is set from task if available
|
||||
for content in Content.objects.select_related('task').all():
|
||||
changed = False
|
||||
if content.task and content.task.entity_type and not content.entity_type:
|
||||
content.entity_type = content.task.entity_type
|
||||
changed = True
|
||||
if content.task and content.task.cluster_role and not content.cluster_role:
|
||||
content.cluster_role = content.task.cluster_role
|
||||
changed = True
|
||||
if not content.entity_type:
|
||||
content.entity_type = 'post'
|
||||
changed = True
|
||||
if changed:
|
||||
content.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('writer', '0005_phase3_mark_deprecated_fields'),
|
||||
('planner', '0003_cleanup_remove_deprecated_fields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
# Step 1: Migrate data
|
||||
migrations.RunPython(migrate_deprecated_data, migrations.RunPython.noop),
|
||||
|
||||
# Step 2: Remove deprecated fields from Tasks
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='content_structure',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='content_type',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='content',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='word_count',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='meta_title',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='meta_description',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='assigned_post_id',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='tasks',
|
||||
name='post_url',
|
||||
),
|
||||
|
||||
# Step 4: Remove deprecated fields from Content
|
||||
migrations.RemoveField(
|
||||
model_name='content',
|
||||
name='categories',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='content',
|
||||
name='tags',
|
||||
),
|
||||
]
|
||||
|
||||
@@ -52,11 +52,11 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
search_fields = ['title', 'keywords']
|
||||
|
||||
# Ordering configuration
|
||||
ordering_fields = ['title', 'created_at', 'word_count', 'status']
|
||||
ordering_fields = ['title', 'created_at', 'status']
|
||||
ordering = ['-created_at'] # Default ordering (newest first)
|
||||
|
||||
# Filter configuration (removed deprecated fields)
|
||||
filterset_fields = ['status', 'cluster_id']
|
||||
# Filter configuration
|
||||
filterset_fields = ['status', 'entity_type', 'cluster_role', 'cluster_id']
|
||||
|
||||
def perform_create(self, serializer):
|
||||
"""Require explicit site_id and sector_id - no defaults."""
|
||||
|
||||
Reference in New Issue
Block a user