forked from rc/aircox
lolilol
This commit is contained in:
@ -39,22 +39,19 @@ class TrackInline (SortableTabularInline):
|
||||
extra = 10
|
||||
|
||||
|
||||
class DescriptionAdmin (admin.ModelAdmin):
|
||||
fields = [ 'name', 'tags', 'description' ]
|
||||
class NameableAdmin (admin.ModelAdmin):
|
||||
fields = [ 'name' ]
|
||||
|
||||
def tags (obj):
|
||||
return ', '.join(obj.tags.names())
|
||||
|
||||
list_display = ['id', 'name', tags]
|
||||
list_display = ['id', 'name']
|
||||
list_filter = []
|
||||
search_fields = ['name',]
|
||||
|
||||
|
||||
@admin.register(Sound)
|
||||
class SoundAdmin (DescriptionAdmin):
|
||||
class SoundAdmin (NameableAdmin):
|
||||
fields = None
|
||||
fieldsets = [
|
||||
(None, { 'fields': DescriptionAdmin.fields + ['path' ] } ),
|
||||
(None, { 'fields': NameableAdmin.fields + ['path' ] } ),
|
||||
(None, { 'fields': ['duration', 'date', 'fragment' ] } )
|
||||
]
|
||||
|
||||
@ -66,15 +63,15 @@ class StreamAdmin (SortableModelAdmin):
|
||||
|
||||
|
||||
@admin.register(Program)
|
||||
class ProgramAdmin (DescriptionAdmin):
|
||||
fields = DescriptionAdmin.fields + ['stream']
|
||||
class ProgramAdmin (NameableAdmin):
|
||||
fields = NameableAdmin.fields + ['stream']
|
||||
inlines = [ ScheduleInline ]
|
||||
|
||||
|
||||
@admin.register(Episode)
|
||||
class EpisodeAdmin (DescriptionAdmin):
|
||||
list_filter = ['program'] + DescriptionAdmin.list_filter
|
||||
fields = DescriptionAdmin.fields + ['sounds']
|
||||
class EpisodeAdmin (NameableAdmin):
|
||||
list_filter = ['program'] + NameableAdmin.list_filter
|
||||
fields = NameableAdmin.fields + ['sounds']
|
||||
|
||||
inlines = (TrackInline, DiffusionInline)
|
||||
|
||||
|
@ -24,20 +24,11 @@ def date_or_default (date, date_only = False):
|
||||
return date
|
||||
|
||||
|
||||
class Description (models.Model):
|
||||
class Nameable (models.Model):
|
||||
name = models.CharField (
|
||||
_('name'),
|
||||
max_length = 128,
|
||||
)
|
||||
description = models.TextField (
|
||||
_('description'),
|
||||
max_length = 1024,
|
||||
blank = True, null = True
|
||||
)
|
||||
tags = TaggableManager(
|
||||
_('tags'),
|
||||
blank = True,
|
||||
)
|
||||
|
||||
def get_slug_name (self):
|
||||
return slugify(self.name)
|
||||
@ -51,7 +42,7 @@ class Description (models.Model):
|
||||
abstract = True
|
||||
|
||||
|
||||
class Track (Description):
|
||||
class Track (Nameable):
|
||||
# There are no nice solution for M2M relations ship (even without
|
||||
# through) in django-admin. So we unfortunately need to make one-
|
||||
# to-one relations and add a position argument
|
||||
@ -68,6 +59,10 @@ class Track (Description):
|
||||
default = 0,
|
||||
help_text=_('position in the playlist'),
|
||||
)
|
||||
tags = TaggableManager(
|
||||
_('tags'),
|
||||
blank = True,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return ' '.join([self.artist, ':', self.name ])
|
||||
@ -77,7 +72,7 @@ class Track (Description):
|
||||
verbose_name_plural = _('Tracks')
|
||||
|
||||
|
||||
class Sound (Description):
|
||||
class Sound (Nameable):
|
||||
"""
|
||||
A Sound is the representation of a sound, that can be:
|
||||
- An episode podcast/complete record
|
||||
@ -134,7 +129,7 @@ class Sound (Description):
|
||||
if not self.pk:
|
||||
self.date = self.get_mtime()
|
||||
|
||||
super(Sound, self).save(*args, **kwargs)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__ (self):
|
||||
return '/'.join(self.path.split('/')[-3:])
|
||||
@ -393,7 +388,7 @@ class Stream (models.Model):
|
||||
return '#{} {}'.format(self.priority, self.name)
|
||||
|
||||
|
||||
class Program (Description):
|
||||
class Program (Nameable):
|
||||
stream = models.ForeignKey(
|
||||
Stream,
|
||||
verbose_name = _('stream'),
|
||||
@ -419,7 +414,7 @@ class Program (Description):
|
||||
return schedule
|
||||
|
||||
|
||||
class Episode (Description):
|
||||
class Episode (Nameable):
|
||||
program = models.ForeignKey(
|
||||
Program,
|
||||
verbose_name = _('program'),
|
||||
|
Reference in New Issue
Block a user