Use a signal to update Artist slug
This commit is contained in:
parent
15f016ad56
commit
582520ddff
|
@ -1,14 +1,11 @@
|
|||
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
|
||||
|
||||
|
||||
class Artist(models.Model):
|
||||
""" An Artist of the label.
|
||||
|
||||
Attributes:
|
||||
name: project / band name
|
||||
image: image file associated with this project
|
||||
"""
|
||||
""" An Artist of the label. """
|
||||
name = models.CharField(max_length = 64)
|
||||
slug = models.SlugField()
|
||||
image = models.ImageField(upload_to = "artists")
|
||||
|
@ -20,15 +17,15 @@ class Artist(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.slug = slugify(self.name)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta(object):
|
||||
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):
|
||||
""" A release (album, EP, ...) of the label.
|
||||
|
@ -47,7 +44,7 @@ class Release(models.Model):
|
|||
ident = models.IntegerField()
|
||||
title = models.CharField(max_length = 256)
|
||||
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")
|
||||
year = models.IntegerField()
|
||||
embed = models.TextField(blank = True)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
def get_catalog_tag_from_id(ident):
|
||||
return "IDRE{:0>3d}".format(ident)
|
||||
|
||||
|
|
Loading…
Reference in a new issue