Implemented Store into admin pages.
This commit is contained in:
parent
ba1f6f05da
commit
3afc5c7a3a
1 changed files with 42 additions and 8 deletions
|
@ -3,7 +3,7 @@ from django.db import models
|
|||
from django.forms import TextInput
|
||||
|
||||
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):
|
||||
|
@ -13,6 +13,13 @@ class ArtistInline(admin.TabularInline):
|
|||
extra = 0
|
||||
|
||||
|
||||
class StoreInline(admin.TabularInline):
|
||||
model = Song.stores.through
|
||||
verbose_name = 'data store'
|
||||
verbose_name_plural = 'data stores'
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(Album)
|
||||
class AlbumAdmin(admin.ModelAdmin):
|
||||
# Detail List display
|
||||
|
@ -101,6 +108,28 @@ class GameAdmin(admin.ModelAdmin):
|
|||
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)
|
||||
class SongAdmin(admin.ModelAdmin):
|
||||
formfield_overrides = {
|
||||
|
@ -123,8 +152,7 @@ class SongAdmin(admin.ModelAdmin):
|
|||
|
||||
# Edit Form display
|
||||
exclude = ('artists',)
|
||||
readonly_fields = ('length',
|
||||
'last_played',
|
||||
readonly_fields = ('last_played',
|
||||
'num_played',
|
||||
'created_date',
|
||||
'modified_date',
|
||||
|
@ -137,8 +165,8 @@ class SongAdmin(admin.ModelAdmin):
|
|||
('Main', {
|
||||
'fields': ('song_type',
|
||||
'title',
|
||||
'path',
|
||||
'published_date')
|
||||
'published_date',
|
||||
'current_store')
|
||||
}),
|
||||
('Stats', {
|
||||
'classes': ('collapse',),
|
||||
|
@ -146,8 +174,7 @@ class SongAdmin(admin.ModelAdmin):
|
|||
'modified_date',
|
||||
'last_played',
|
||||
'num_played',
|
||||
'next_play',
|
||||
'length')
|
||||
'next_play')
|
||||
}),
|
||||
('Album', {
|
||||
'fields': ('album',)
|
||||
|
@ -156,7 +183,14 @@ class SongAdmin(admin.ModelAdmin):
|
|||
'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):
|
||||
return ', '.join([a.full_name for a in obj.artists.all()])
|
||||
|
|
Loading…
Reference in a new issue