|
|
@ -11,7 +11,7 @@ from ..models import HadisSect, HadisCategory |
|
|
|
|
|
|
|
|
class HadisSectAdmin(ModelAdmin): |
|
|
class HadisSectAdmin(ModelAdmin): |
|
|
"""Admin for HadisSect model""" |
|
|
"""Admin for HadisSect model""" |
|
|
list_display = ('sect_type', 'title', 'is_active', 'order') |
|
|
|
|
|
|
|
|
list_display = ('sect_type', 'display_title', 'is_active', 'order') |
|
|
list_filter = ('sect_type', 'is_active') |
|
|
list_filter = ('sect_type', 'is_active') |
|
|
search_fields = ('title',) |
|
|
search_fields = ('title',) |
|
|
ordering = ('order',) |
|
|
ordering = ('order',) |
|
|
@ -22,6 +22,15 @@ class HadisSectAdmin(ModelAdmin): |
|
|
}), |
|
|
}), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def display_title(self, obj): |
|
|
|
|
|
"""Extracts text from the title JSON list""" |
|
|
|
|
|
try: |
|
|
|
|
|
return obj.title[0]['text'] |
|
|
|
|
|
except (IndexError, KeyError, TypeError, AttributeError): |
|
|
|
|
|
return "No Title" |
|
|
|
|
|
|
|
|
|
|
|
display_title.short_description = _('Title') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HadisCategoryAdmin(DraggableMPTTAdmin, ModelAdmin): |
|
|
class HadisCategoryAdmin(DraggableMPTTAdmin, ModelAdmin): |
|
|
"""Admin for HadisCategory model with MPTT tree support""" |
|
|
"""Admin for HadisCategory model with MPTT tree support""" |
|
|
@ -43,8 +52,17 @@ class HadisCategoryAdmin(DraggableMPTTAdmin, ModelAdmin): |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def indented_title(self, instance): |
|
|
def indented_title(self, instance): |
|
|
"""Display indented title for tree structure""" |
|
|
|
|
|
return f"{'—' * instance.level} {instance.title}" |
|
|
|
|
|
|
|
|
"""Display indented title for tree structure using JSON text""" |
|
|
|
|
|
try: |
|
|
|
|
|
# Extract text from the first element of the title list |
|
|
|
|
|
title_text = instance.title[0]['text'] |
|
|
|
|
|
except (IndexError, KeyError, TypeError, AttributeError): |
|
|
|
|
|
title_text = "No Title" |
|
|
|
|
|
|
|
|
|
|
|
# DraggableMPTTAdmin works best if you don't mess with the HTML too much, |
|
|
|
|
|
# but here is your requested dash indentation style combined with clean text: |
|
|
|
|
|
return f"{'—' * instance.level} {title_text}" |
|
|
|
|
|
|
|
|
indented_title.short_description = _('Title') |
|
|
indented_title.short_description = _('Title') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|