From 0586983602892c1c8686f1429ddac8e66a3dd758 Mon Sep 17 00:00:00 2001 From: ab623 Date: Wed, 17 Apr 2024 22:18:23 +0100 Subject: [PATCH] Show proper name for bookmark assets in admin (#708) --- bookmarks/admin.py | 8 ++++++-- bookmarks/models.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bookmarks/admin.py b/bookmarks/admin.py index 532c1a9..ca6423a 100644 --- a/bookmarks/admin.py +++ b/bookmarks/admin.py @@ -200,9 +200,13 @@ class AdminBookmark(admin.ModelAdmin): class AdminBookmarkAsset(admin.ModelAdmin): - list_display = ("display_name", "date_created", "status") + @admin.display(description="Display Name") + def custom_display_name(self, obj): + return str(obj) + + list_display = ("custom_display_name", "date_created", "status") search_fields = ( - "display_name", + "custom_display_name", "file", ) list_filter = ("status",) diff --git a/bookmarks/models.py b/bookmarks/models.py index 9087829..96bbb1f 100644 --- a/bookmarks/models.py +++ b/bookmarks/models.py @@ -118,6 +118,9 @@ class BookmarkAsset(models.Model): pass super().save(*args, **kwargs) + def __str__(self): + return self.display_name or f"Bookmark Asset #{self.pk}" + @receiver(post_delete, sender=BookmarkAsset) def bookmark_asset_deleted(sender, instance, **kwargs):