report-note: admin: Add a link to relevant song

Previously, the admin could not directly move from a report note to
its corresponding song. This commit adds a link that will go
directly to the "change" page for the corresponding song.
This commit is contained in:
Daan Sprenkels
2020-06-15 15:18:37 +02:00
parent 4a1df11b40
commit 1b5b5106ba

View File

@ -1,4 +1,6 @@
from django.contrib import admin from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html
from .models import ReportNote, Song from .models import ReportNote, Song
@ -32,4 +34,11 @@ class SongAdmin(admin.ModelAdmin):
class ReportNoteAdmin(admin.ModelAdmin): class ReportNoteAdmin(admin.ModelAdmin):
list_display = ('song', 'note', 'user') list_display = ('song', 'note', 'user')
search_fields = ('song__artist', 'song__title', 'user__name') search_fields = ('song__artist', 'song__title', 'user__name')
readonly_fields = ('song',) readonly_fields = ('song_link',)
@staticmethod
def song_link(note):
url = reverse("admin:songs_song_change", args=(note.song.id,))
return format_html("<a href='{url}'>{song}</a>", url=url, song=note.song)
song_link.short_description = "Song link"