SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit adaa107f authored by George Katsikas's avatar George Katsikas :goat:
Browse files

improve notes admin page

parent 717996ca
No related branches found
No related tags found
No related merge requests found
...@@ -2,13 +2,22 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" ...@@ -2,13 +2,22 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3" __license__ = "AGPL v3"
from django.contrib import admin from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html
from pins.models import Note from pins.models import Note
@admin.register(Note) @admin.register(Note)
class NoteAdmin(admin.ModelAdmin): class NoteAdmin(admin.ModelAdmin):
list_display = ("id", "regarding__object", "title", "author", "created", "modified") list_display = (
"id",
"regarding_object_links",
"title",
"author",
"created",
"modified",
)
list_filter = ("created", "modified", "visibility", "regarding_content_type") list_filter = ("created", "modified", "visibility", "regarding_content_type")
search_fields = ("title", "author__username") search_fields = ("title", "author__username")
date_hierarchy = "created" date_hierarchy = "created"
...@@ -25,5 +34,14 @@ class NoteAdmin(admin.ModelAdmin): ...@@ -25,5 +34,14 @@ class NoteAdmin(admin.ModelAdmin):
) )
autocomplete_fields = ("author",) autocomplete_fields = ("author",)
def regarding__object(self, obj): def regarding_object_links(self, obj):
return str(obj.regarding) 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>"
)
...@@ -70,7 +70,7 @@ def _hx_notes_list(request, regarding_content_type, regarding_object_id): ...@@ -70,7 +70,7 @@ def _hx_notes_list(request, regarding_content_type, regarding_object_id):
can_create_notes = request.user.has_perm("pins.can_add_notes") can_create_notes = request.user.has_perm("pins.can_add_notes")
# Filter according to the visibility of the notes # Filter according to the visibility of the notes
notes = notes.visible_to(request.user, object) notes = notes.visible_to(request.user, object.__class__)
context = { context = {
"object": object, "object": object,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment