From d366a9a455bbca50642dd3cf9b6ff98043b06e85 Mon Sep 17 00:00:00 2001 From: Rafi Date: Thu, 16 Mar 2023 14:35:28 +0800 Subject: [PATCH] Admin: Displaying Model Fields --- chat/admin.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/chat/admin.py b/chat/admin.py index 3ce3d6b..47ac233 100644 --- a/chat/admin.py +++ b/chat/admin.py @@ -2,10 +2,22 @@ from .models import Conversation, Message, Setting -admin.site.register(Conversation) -admin.site.register(Message) -class SettingAdmin(admin.ModelAdmin): - list_display = ('name', 'value') +@admin.register(Conversation) +class ConversationAdmin(admin.ModelAdmin): + list_display = ('id', 'user', 'topic', 'created_at') + + +@admin.register(Message) +class MessageAdmin(admin.ModelAdmin): + list_display = ('id', 'get_conversation_topic', 'message', 'is_bot', 'created_at') + + def get_conversation_topic(self, obj): + return obj.conversation.topic -admin.site.register(Setting, SettingAdmin) \ No newline at end of file + get_conversation_topic.short_description = 'Conversation Topic' + + +@admin.register(Setting) +class SettingAdmin(admin.ModelAdmin): + list_display = ('name', 'value') \ No newline at end of file