From 68df3de4a7f0846f822f0a4aeb0f68cd552a090a Mon Sep 17 00:00:00 2001 From: Shgck Date: Sat, 2 May 2015 13:06:39 +0200 Subject: [PATCH] Added slug in database (needs db sync) --- label/admin.py | 8 ++++++-- label/models.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/label/admin.py b/label/admin.py index b542a12..d9f3e41 100644 --- a/label/admin.py +++ b/label/admin.py @@ -2,5 +2,9 @@ from django.contrib import admin from label.models import * -admin.site.register(Artist) -admin.site.register(Release) \ No newline at end of file +class ArtistAdmin(admin.ModelAdmin): + exclude = ("slug",) + + +admin.site.register(Artist, ArtistAdmin) +admin.site.register(Release) diff --git a/label/models.py b/label/models.py index e060225..379b10a 100644 --- a/label/models.py +++ b/label/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.template.defaultfilters import slugify class Artist(models.Model): @@ -9,6 +10,7 @@ class Artist(models.Model): image: image file associated with this project """ 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) @@ -18,10 +20,16 @@ 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",) +rel_types_hint = "full-length (0), EP (1), Split (2), Démo (3)" + class Release(models.Model): """ A release (album, EP, ...) of the label. @@ -35,13 +43,11 @@ class Release(models.Model): release_type: see below year: year of release cover: image file associated to this release - - Release types: full-length (0), EP (1), Split (2), Démo (3) """ ident = models.IntegerField() title = models.CharField(max_length = 256) contributors = models.ManyToManyField(Artist) - release_type = models.IntegerField(default = 0) + 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)