This commit is contained in:
IGNY8 VPS (Salman)
2025-11-29 08:59:31 +00:00
parent 4bea79a76d
commit 4237c203b4
18 changed files with 507 additions and 52 deletions

View File

@@ -86,11 +86,12 @@ class ImagesAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
@admin.register(Content)
class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
list_display = ['title', 'content_type', 'content_structure', 'site', 'sector', 'source', 'status', 'created_at']
list_display = ['title', 'content_type', 'content_structure', 'site', 'sector', 'source', 'status', 'get_taxonomy_count', 'created_at']
list_filter = ['content_type', 'content_structure', 'source', 'status', 'site', 'sector', 'created_at']
search_fields = ['title', 'content_html', 'external_url']
ordering = ['-created_at']
readonly_fields = ['created_at', 'updated_at']
readonly_fields = ['created_at', 'updated_at', 'word_count']
filter_horizontal = ['taxonomy_terms'] # Add many-to-many widget for taxonomy terms
fieldsets = (
('Basic Info', {
@@ -99,8 +100,16 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
('Content Classification', {
'fields': ('content_type', 'content_structure', 'source')
}),
('Taxonomy Terms (Tags & Categories)', {
'fields': ('taxonomy_terms',),
'description': 'Select tags and categories for this content'
}),
('Content', {
'fields': ('content_html',)
'fields': ('content_html', 'word_count')
}),
('SEO', {
'fields': ('meta_title', 'meta_description', 'primary_keyword', 'secondary_keywords'),
'classes': ('collapse',)
}),
('WordPress Sync', {
'fields': ('external_id', 'external_url'),
@@ -112,6 +121,11 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
}),
)
def get_taxonomy_count(self, obj):
"""Display count of associated taxonomy terms"""
return obj.taxonomy_terms.count()
get_taxonomy_count.short_description = 'Taxonomy Count'
def get_site_display(self, obj):
"""Safely get site name"""
try:

View File

@@ -154,6 +154,8 @@ class ContentSerializer(serializers.ModelSerializer):
cluster_name = serializers.SerializerMethodField()
sector_name = serializers.SerializerMethodField()
taxonomy_terms_data = serializers.SerializerMethodField()
tags = serializers.SerializerMethodField()
categories = serializers.SerializerMethodField()
has_image_prompts = serializers.SerializerMethodField()
image_status = serializers.SerializerMethodField()
has_generated_images = serializers.SerializerMethodField()
@@ -175,6 +177,8 @@ class ContentSerializer(serializers.ModelSerializer):
'content_type',
'content_structure',
'taxonomy_terms_data',
'tags',
'categories',
'external_id',
'external_url',
'source',
@@ -246,6 +250,20 @@ class ContentSerializer(serializers.ModelSerializer):
for term in obj.taxonomy_terms.all()
]
def get_tags(self, obj):
"""Get only tags (taxonomy_type='tag')"""
return [
term.name
for term in obj.taxonomy_terms.filter(taxonomy_type='tag')
]
def get_categories(self, obj):
"""Get only categories (taxonomy_type='category')"""
return [
term.name
for term in obj.taxonomy_terms.filter(taxonomy_type='category')
]
def get_has_image_prompts(self, obj):
"""Check if content has any image prompts (images with prompts)"""
return obj.images.filter(prompt__isnull=False).exclude(prompt='').exists()