From 7251dbb70170d120643d40a535c7a69218e90378 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 18 Mar 2025 17:35:25 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20separate=20note=20related?= =?UTF-8?q?=20links=20in=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scipost_django/pins/admin.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/scipost_django/pins/admin.py b/scipost_django/pins/admin.py index 7809af2a5..077291306 100644 --- a/scipost_django/pins/admin.py +++ b/scipost_django/pins/admin.py @@ -12,21 +12,22 @@ from pins.models import Note class NoteAdmin(admin.ModelAdmin): list_display = ( "id", - "regarding_object_links", + "web_link", + "admin_link", "title", "author", "created", "modified", ) - list_filter = ("created", "modified", "visibility", "regarding_content_type") + list_filter = ("created", "modified", "visibility") search_fields = ("title", "author__username") date_hierarchy = "created" ordering = ("-created",) - readonly_fields = ("created", "modified", "regarding") + readonly_fields = ("created", "modified", "web_link", "admin_link") fields = ( + "web_link", "title", "description", - "regarding", "visibility", "author", "created", @@ -34,14 +35,16 @@ class NoteAdmin(admin.ModelAdmin): ) autocomplete_fields = ("author",) - def regarding_object_links(self, obj): + def admin_link(self, obj): content_type = obj.regarding_content_type - model = content_type.model_class() - regarding = model.objects.get(pk=obj.regarding_object_id) admin_url = f"admin:{content_type.app_label}_{content_type.model}_change" return format_html( - "<div style='display: flex; justify-content:space-between;>" - f'<a href="{regarding.get_absolute_url()}">{regarding}</a>' - f'<a href="{reverse(admin_url, args=[obj.regarding_object_id])}">[admin]</a>' - "</div>" + '<a href="{}">[admin]</a>', + reverse(admin_url, args=[obj.regarding_object_id]), ) + + def web_link(self, obj): + content_type = obj.regarding_content_type + model = content_type.model_class() + regarding = model.objects.get(pk=obj.regarding_object_id) + return format_html(f'<a href="{regarding.get_absolute_url()}">{regarding}</a>') -- GitLab