mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 09:12:23 +01:00
Marietje 4.1: Addition of Django REST framework, Swagger, Dark mode and updates to Django and Bootstrap
This commit is contained in:
@ -9,35 +9,36 @@ from .models import ReportNote, Song
|
||||
class ReportNoteInline(admin.StackedInline):
|
||||
model = ReportNote
|
||||
extra = 0
|
||||
autocomplete_fields = ('user',)
|
||||
autocomplete_fields = ("user",)
|
||||
|
||||
|
||||
class SongHasReportNoteFilter(admin.SimpleListFilter):
|
||||
title = 'report notes'
|
||||
parameter_name = 'reportnotes'
|
||||
title = "report notes"
|
||||
parameter_name = "reportnotes"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return (
|
||||
('yes', 'yes'),
|
||||
('no', 'no'),
|
||||
("yes", "yes"),
|
||||
("no", "no"),
|
||||
)
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
queryset = queryset.annotate(num_reports=Count('reportnote'))
|
||||
if self.value() == 'yes':
|
||||
queryset = queryset.annotate(num_reports=Count("reportnote"))
|
||||
if self.value() == "yes":
|
||||
return queryset.exclude(num_reports=0)
|
||||
if self.value() == 'no':
|
||||
if self.value() == "no":
|
||||
return queryset.filter(num_reports=0)
|
||||
return queryset
|
||||
|
||||
|
||||
@admin.register(Song)
|
||||
class SongAdmin(admin.ModelAdmin):
|
||||
list_display = ('artist', 'title', 'user_name', 'reports')
|
||||
list_display_links = ('artist', 'title')
|
||||
list_display = ("artist", "title", "user_name", "reports")
|
||||
list_display_links = ("artist", "title")
|
||||
list_filter = (SongHasReportNoteFilter,)
|
||||
search_fields = ('artist', 'title', 'user__name')
|
||||
search_fields = ("artist", "title", "user__name")
|
||||
inlines = [ReportNoteInline]
|
||||
autocomplete_fields = ('user',)
|
||||
autocomplete_fields = ("user",)
|
||||
|
||||
@staticmethod
|
||||
def reports(song):
|
||||
@ -49,19 +50,20 @@ class SongAdmin(admin.ModelAdmin):
|
||||
try:
|
||||
return song.user.name
|
||||
except AttributeError:
|
||||
return '<unknown>'
|
||||
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):
|
||||
exclude = ('song',)
|
||||
list_display = ('song', 'note', 'user')
|
||||
search_fields = ('song__artist', 'song__title', 'user__name')
|
||||
autocomplete_fields = ('user',)
|
||||
readonly_fields = ('song_link',)
|
||||
exclude = ("song",)
|
||||
list_display = ("song", "note", "user")
|
||||
search_fields = ("song__artist", "song__title", "user__name")
|
||||
autocomplete_fields = ("user",)
|
||||
readonly_fields = ("song_link",)
|
||||
|
||||
@staticmethod
|
||||
def song_link(note):
|
||||
|
||||
Reference in New Issue
Block a user