From 362802585ceeaad1978da41a8a18518757d259c8 Mon Sep 17 00:00:00 2001 From: Rachael Robinson <23265724+rachaelcodes@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:39:22 +0100 Subject: [PATCH] make admin more readable --- django_app/redbox_app/redbox_core/admin.py | 13 +++++++++++-- django_app/redbox_app/redbox_core/models.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/django_app/redbox_app/redbox_core/admin.py b/django_app/redbox_app/redbox_core/admin.py index 86dfa419d..eb72702dc 100644 --- a/django_app/redbox_app/redbox_core/admin.py +++ b/django_app/redbox_app/redbox_core/admin.py @@ -30,10 +30,18 @@ class FileAdmin(admin.ModelAdmin): date_hierarchy = "created_at" +class CitationInline(admin.StackedInline): + model = models.Citation + ordering = ("modified_at",) + + extra = 1 + + class ChatMessageAdmin(admin.ModelAdmin): - list_display = ["chat_history", "get_user", "text", "role", "route", "created_at"] + list_display = ["text", "role", "get_user", "chat_history", "route", "created_at"] list_filter = ["role", "route", "chat_history__users"] date_hierarchy = "created_at" + inlines = [CitationInline] @admin.display(ordering="chat_history__users", description="User") def get_user(self, obj): @@ -45,6 +53,7 @@ class ChatMessageInline(admin.StackedInline): ordering = ("modified_at",) readonly_fields = ["modified_at", "source_files"] extra = 1 + show_change_link = True # allows users to click through to look at Citations class ChatHistoryAdmin(admin.ModelAdmin): @@ -76,7 +85,7 @@ def export_as_csv(self, request, queryset): # noqa:ARG002 class CitationAdmin(admin.ModelAdmin): - list_display = ["chat_message", "text", "get_user", "file"] + list_display = ["text", "get_user", "chat_message", "file"] list_filter = ["chat_message__chat_history__users"] @admin.display(ordering="chat_message__chat_history__users", description="User") diff --git a/django_app/redbox_app/redbox_core/models.py b/django_app/redbox_app/redbox_core/models.py index 82471f36d..b3ee05e36 100644 --- a/django_app/redbox_app/redbox_core/models.py +++ b/django_app/redbox_app/redbox_core/models.py @@ -244,4 +244,4 @@ class ChatMessage(UUIDPrimaryKeyBase, TimeStampedModel): source_files = models.ManyToManyField(File, through=Citation) def __str__(self) -> str: # pragma: no cover - return f"{self.chat_history} - {self.text} - {self.role}" + return f"{self.text} - {self.role}"