2017-12-29 14:56:47 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
from core.behaviors import Timestampable
|
|
|
|
from .behaviors import Disableable, Publishable
|
|
|
|
from .managers import SongManager
|
|
|
|
|
|
|
|
|
|
|
|
class Album(Disableable, Publishable, Timestampable, models.Model):
|
|
|
|
"""
|
|
|
|
A model for a music album.
|
|
|
|
"""
|
|
|
|
title = models.CharField(_('title'), max_length=255, unique=True)
|
|
|
|
|
2018-01-05 20:18:12 +00:00
|
|
|
sorted_title = models.CharField(_('naturalized title'),
|
|
|
|
db_index=True,
|
|
|
|
editable=False,
|
|
|
|
max_length=255)
|
|
|
|
|
2018-01-12 21:34:43 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['sorted_title', ]
|
|
|
|
|
2017-12-29 14:56:47 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
|
|
|
|
class Artist(Disableable, Publishable, Timestampable, models.Model):
|
|
|
|
"""
|
|
|
|
A model for a music artist.
|
|
|
|
"""
|
|
|
|
alias = models.CharField(_('alias'), max_length=127, blank=True)
|
|
|
|
first_name = models.CharField(_('first name'), max_length=127, blank=True)
|
|
|
|
last_name = models.CharField(_('last name'), max_length=127, blank=True)
|
|
|
|
|
2018-01-05 20:18:12 +00:00
|
|
|
sorted_full_name = models.CharField(_('naturalized full name'),
|
|
|
|
db_index=True,
|
|
|
|
editable=False,
|
|
|
|
max_length=255)
|
2018-01-04 21:29:29 +00:00
|
|
|
|
2018-01-12 21:34:43 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['sorted_full_name', ]
|
|
|
|
|
2017-12-29 14:56:47 +00:00
|
|
|
@property
|
|
|
|
def full_name(self):
|
|
|
|
if not self.alias:
|
|
|
|
return '{} {}'.format(self.first_name, self.last_name)
|
|
|
|
else:
|
|
|
|
if not self.first_name or not self.last_name:
|
|
|
|
return self.alias
|
|
|
|
else:
|
|
|
|
return '{} "{}" {}'.format(self.first_name,
|
|
|
|
self.alias,
|
|
|
|
self.last_name)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.full_name
|
|
|
|
|
|
|
|
|
|
|
|
class Game(Disableable, Publishable, Timestampable, models.Model):
|
|
|
|
"""
|
|
|
|
A model for a game.
|
|
|
|
"""
|
|
|
|
title = models.CharField(_('title'), max_length=255, unique=True)
|
|
|
|
|
2018-01-05 20:18:12 +00:00
|
|
|
sorted_title = models.CharField(_('naturalized title'),
|
|
|
|
db_index=True,
|
|
|
|
editable=False,
|
|
|
|
max_length=255)
|
|
|
|
|
2018-01-12 21:34:43 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['sorted_title', ]
|
|
|
|
|
2017-12-29 14:56:47 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
|
|
|
|
class Song(Disableable, Publishable, Timestampable, models.Model):
|
|
|
|
"""
|
|
|
|
A model for a song.
|
|
|
|
"""
|
|
|
|
JINGLE = 'J'
|
|
|
|
SONG = 'S'
|
|
|
|
TYPE_CHOICES = (
|
|
|
|
(JINGLE, 'Jingle'),
|
|
|
|
(SONG, 'Song'),
|
|
|
|
)
|
|
|
|
album = models.ForeignKey(Album,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
blank=True)
|
|
|
|
artists = models.ManyToManyField(Artist)
|
|
|
|
game = models.ForeignKey(Game,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
blank=True)
|
|
|
|
song_type = models.CharField(_('song type'),
|
|
|
|
max_length=1,
|
|
|
|
choices=TYPE_CHOICES,
|
|
|
|
default=SONG)
|
|
|
|
title = models.CharField(_('title'), max_length=255)
|
|
|
|
num_played = models.PositiveIntegerField(_('number of times played'),
|
|
|
|
default=0)
|
|
|
|
last_played = models.DateTimeField(_('was last played'),
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
editable=False)
|
|
|
|
length = models.DecimalField(_('song length (in seconds)'),
|
|
|
|
max_digits=8,
|
|
|
|
decimal_places=2,
|
|
|
|
null=True,
|
|
|
|
blank=True)
|
|
|
|
path = models.TextField(_('absolute path to song file'))
|
|
|
|
|
2018-01-05 20:18:12 +00:00
|
|
|
sorted_title = models.CharField(_('naturalized title'),
|
|
|
|
db_index=True,
|
|
|
|
editable=False,
|
|
|
|
max_length=255)
|
|
|
|
|
2017-12-29 14:56:47 +00:00
|
|
|
objects = models.Manager()
|
|
|
|
music = SongManager()
|
|
|
|
|
2018-01-12 21:34:43 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['sorted_title', ]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def full_title(self):
|
2017-12-29 14:56:47 +00:00
|
|
|
if self.song_type == 'J':
|
|
|
|
return self.title
|
|
|
|
else:
|
|
|
|
all_artists = ', '.join([a.full_name for a in self.artists.all()])
|
|
|
|
return '{} - {} ({})'.format(self.game.title,
|
|
|
|
self.title,
|
|
|
|
all_artists)
|
2018-01-12 21:34:43 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|