from django.db import models from django.db.models.signals import pre_save from django.dispatch.dispatcher import receiver from django.template.defaultfilters import slugify ART_GENRE_HINT = 'lowercase please!' ART_DESC_HINT = 'Markdown or HTML formatting supported' ART_TYPES_HINT = 'main roster (0), side project (1)' class Artist(models.Model): """ An Artist of the label. """ name = models.CharField(max_length=64) slug = models.SlugField() image = models.ImageField(upload_to='artists') url_bandcamp = models.URLField(blank=True) url_soundcloud = models.URLField(blank=True) genre = models.CharField(max_length=256, help_text=ART_GENRE_HINT) description = models.TextField(blank=True, help_text=ART_DESC_HINT) artist_type = models.IntegerField(default=0, help_text=ART_TYPES_HINT) def __str__(self): return self.name class Meta(object): ordering = ('name',) @receiver(pre_save, sender = Artist) def _artist_pre_save(sender, instance, **kwargs): instance.slug = slugify(instance.name) class Release(models.Model): """ A release (album, EP, ...) of the label. Each release has an associated number "ident" to use in the catalog. It has of course a title, several possible artists, and other informations. Attributes: ident: catalog number title: release title contributors: list of Artists who contributed to this release release_type: see TYPE_HINT year: year of release cover: image file associated to this release """ TYPE_HINT = 'full-length (0), EP (1), Split (2), Démo (3)' EMBED_HINT = 'HTML iframe -- for Bandcamp, add the whole tracklist' ident = models.IntegerField() title = models.CharField(max_length=256) contributors = models.ManyToManyField(Artist) release_type = models.IntegerField(default=0, help_text=TYPE_HINT) cover = models.ImageField(upload_to='releases') year = models.IntegerField() embed = models.TextField(blank=True, help_text=EMBED_HINT) description = models.TextField(blank=True) def __str__(self): return self.title class Meta(object): ordering = ('ident', 'title')