1
0
Fork 0

Use a signal to update Artist slug

This commit is contained in:
Shgck 2016-02-01 18:42:01 +01:00
parent 15f016ad56
commit 582520ddff
2 changed files with 11 additions and 13 deletions

View file

@ -1,14 +1,11 @@
from django.db import models 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 from django.template.defaultfilters import slugify
class Artist(models.Model): class Artist(models.Model):
""" An Artist of the label. """ An Artist of the label. """
Attributes:
name: project / band name
image: image file associated with this project
"""
name = models.CharField(max_length = 64) name = models.CharField(max_length = 64)
slug = models.SlugField() slug = models.SlugField()
image = models.ImageField(upload_to = "artists") image = models.ImageField(upload_to = "artists")
@ -20,15 +17,15 @@ class Artist(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
def save(self, *args, **kwargs):
self.slug = slugify(self.name)
super().save(*args, **kwargs)
class Meta(object): class Meta(object):
ordering = ("name",) ordering = ("name",)
@receiver(pre_save, sender = Artist)
def _artist_pre_save(sender, instance, **kwargs):
instance.slug = slugify(instance.name)
rel_types_hint = "full-length (0), EP (1), Split (2), Démo (3)"
REL_TYPES_HINT = "full-length (0), EP (1), Split (2), Démo (3)"
class Release(models.Model): class Release(models.Model):
""" A release (album, EP, ...) of the label. """ A release (album, EP, ...) of the label.
@ -47,7 +44,7 @@ class Release(models.Model):
ident = models.IntegerField() ident = models.IntegerField()
title = models.CharField(max_length = 256) title = models.CharField(max_length = 256)
contributors = models.ManyToManyField(Artist) contributors = models.ManyToManyField(Artist)
release_type = models.IntegerField(default = 0, help_text = rel_types_hint) release_type = models.IntegerField(default = 0, help_text = REL_TYPES_HINT)
cover = models.ImageField(upload_to = "releases") cover = models.ImageField(upload_to = "releases")
year = models.IntegerField() year = models.IntegerField()
embed = models.TextField(blank = True) embed = models.TextField(blank = True)

View file

@ -1,3 +1,4 @@
def get_catalog_tag_from_id(ident): def get_catalog_tag_from_id(ident):
return "IDRE{:0>3d}".format(ident) return "IDRE{:0>3d}".format(ident)