Implemented Store into admin pages.

This commit is contained in:
RecursiveGreen 2019-06-03 15:03:23 -04:00
parent ba1f6f05da
commit 3afc5c7a3a

View file

@ -3,7 +3,7 @@ from django.db import models
from django.forms import TextInput from django.forms import TextInput
from .actions import change_items, publish_items, remove_items from .actions import change_items, publish_items, remove_items
from .models import Album, Artist, Game, Song from .models import Album, Artist, Game, Song, Store
class ArtistInline(admin.TabularInline): class ArtistInline(admin.TabularInline):
@ -13,6 +13,13 @@ class ArtistInline(admin.TabularInline):
extra = 0 extra = 0
class StoreInline(admin.TabularInline):
model = Song.stores.through
verbose_name = 'data store'
verbose_name_plural = 'data stores'
extra = 0
@admin.register(Album) @admin.register(Album)
class AlbumAdmin(admin.ModelAdmin): class AlbumAdmin(admin.ModelAdmin):
# Detail List display # Detail List display
@ -101,6 +108,28 @@ class GameAdmin(admin.ModelAdmin):
publish_games.short_description = "Publish selected games" publish_games.short_description = "Publish selected games"
@admin.register(Store)
class StoreAdmin(admin.ModelAdmin):
# Detail List display
list_display = ('iri',
'mime_type',
'file_size',
'length')
search_fields = ['iri']
# Edit Form display
readonly_fields = ('created_date', 'modified_date')
fieldsets = (
('Main', {
'fields': ('iri', 'mime_type', 'file_size', 'length')
}),
('Stats', {
'classes': ('collapse',),
'fields': ('created_date', 'modified_date')
})
)
@admin.register(Song) @admin.register(Song)
class SongAdmin(admin.ModelAdmin): class SongAdmin(admin.ModelAdmin):
formfield_overrides = { formfield_overrides = {
@ -123,8 +152,7 @@ class SongAdmin(admin.ModelAdmin):
# Edit Form display # Edit Form display
exclude = ('artists',) exclude = ('artists',)
readonly_fields = ('length', readonly_fields = ('last_played',
'last_played',
'num_played', 'num_played',
'created_date', 'created_date',
'modified_date', 'modified_date',
@ -137,8 +165,8 @@ class SongAdmin(admin.ModelAdmin):
('Main', { ('Main', {
'fields': ('song_type', 'fields': ('song_type',
'title', 'title',
'path', 'published_date',
'published_date') 'current_store')
}), }),
('Stats', { ('Stats', {
'classes': ('collapse',), 'classes': ('collapse',),
@ -146,8 +174,7 @@ class SongAdmin(admin.ModelAdmin):
'modified_date', 'modified_date',
'last_played', 'last_played',
'num_played', 'num_played',
'next_play', 'next_play')
'length')
}), }),
('Album', { ('Album', {
'fields': ('album',) 'fields': ('album',)
@ -156,7 +183,14 @@ class SongAdmin(admin.ModelAdmin):
'fields': ('game',) 'fields': ('game',)
}) })
) )
inlines = [ArtistInline] inlines = [ArtistInline, StoreInline]
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'current_store':
kwargs['queryset'] = Store.objects.filter(
song__pk=request.resolver_match.kwargs['object_id']
)
return super().formfield_for_foreignkey(db_field, request, **kwargs)
def artist_list(self, obj): def artist_list(self, obj):
return ', '.join([a.full_name for a in obj.artists.all()]) return ', '.join([a.full_name for a in obj.artists.all()])