Skip to content

Commit

Permalink
refactor: Update LocationAdmin to display HTML description
Browse files Browse the repository at this point in the history
This commit updates the `LocationAdmin` class in the `admin.py` file to display the HTML description of a location. It adds a new method `description_html` that returns the formatted HTML description if available. The `description_html` method is used in the `list_display` attribute to show the description column in the admin interface.

This change improves the readability and presentation of location descriptions in the application.
  • Loading branch information
hepplerj committed May 29, 2024
1 parent 60c9204 commit b317042
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions manuscript/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ class CodexAdmin(admin.ModelAdmin):
list_display = ("id", "support", "height", "folia", "date")


class LocationAdmin(admin.ModelAdmin):
@admin.register(Location)
class LocationAdmin(ImportExportModelAdmin):
inlines = [LocationAliasInline]
list_display = ("country", "latitude", "longitude", "id")
list_display = ("country", "description_html", "latitude", "longitude", "id")

def description_html(self, obj):
return format_html(obj.description) if obj.description else ""

description_html.short_description = "Description"

def save_related(self, request, form, formsets, change):
super().save_related(request, form, formsets, change)
Expand All @@ -213,12 +219,10 @@ def get_changeform_initial_data(self, request):
admin.site.register(Library, LibraryAdmin)
admin.site.register(EditorialStatus, EditorialStatusAdmin)
admin.site.register(Folio, FolioAdmin)
admin.site.register(Location, LocationAdmin)
admin.site.register(SingleManuscript, SingleManuscriptAdmin)
admin.site.register(Stanza, StanzaAdmin)
admin.site.register(StanzaVariant, StanzaVariantAdmin)

# fix pluralization of codex
admin.site.site_header = "La Sfera Admin"
admin.site.site_title = "La Sfera Admin Portal"
admin.site.index_title = "Welcome to the La Sfera Manuscript Portal"

0 comments on commit b317042

Please sign in to comment.