Song reporting and user stats

This commit is contained in:
Olaf Slomp
2018-12-14 16:59:44 +01:00
committed by Daan Sprenkels
parent 0c1f9cb08d
commit f6fcc63450
17 changed files with 381 additions and 47 deletions

View File

@ -1,20 +1,33 @@
from django.contrib import admin
from .models import Song
from .models import ReportNote, Song
class ReportNoteInline(admin.StackedInline):
model = ReportNote
extra = 0
@admin.register(Song)
class SongAdmin(admin.ModelAdmin):
list_display = ('artist', 'title', 'user_name')
list_display = ('artist', 'title', 'user_name', 'reports')
search_fields = ('artist', 'title', 'user__name')
inlines = [ReportNoteInline]
def reports(self, song):
return ReportNote.objects.filter(song=song).count()
@staticmethod
def user_name(obj):
def user_name(song):
try:
return obj.user.name
return song.user.name
except AttributeError:
return '<unknown>'
@staticmethod
def get_readonly_fields(request, obj=None):
return [] if request.user.is_superuser else ['hash']
return [] if request.user.is_superuser else ['hash']
@admin.register(ReportNote)
class ReportNoteAdmin(admin.ModelAdmin):
list_display = ('song', 'note', 'user')
search_fields = ('song__artist', 'song__title', 'user__name')