mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 09:12:23 +01:00
Song reporting and user stats
This commit is contained in:
committed by
Daan Sprenkels
parent
0c1f9cb08d
commit
f6fcc63450
@ -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')
|
||||
|
||||
Reference in New Issue
Block a user