diff --git a/pyconbalkan/coc/models.py b/pyconbalkan/coc/models.py index ee760e5c..d02f8c06 100644 --- a/pyconbalkan/coc/models.py +++ b/pyconbalkan/coc/models.py @@ -1,6 +1,7 @@ from django.db import models from markdownx.models import MarkdownxField from pyconbalkan.core.models import SingleActiveModel +from django.utils.text import slugify class CodeOfConduct(SingleActiveModel): @@ -16,5 +17,10 @@ class ResponseGuide(SingleActiveModel): description = MarkdownxField(null=True, blank=True) slug = models.CharField(unique=True, blank=True, max_length=100) + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.title) + super(ResponseGuide, self).save(*args, **kwargs) + def __str__(self): return self.title diff --git a/pyconbalkan/news/models.py b/pyconbalkan/news/models.py index fb7bbd22..3bec698d 100644 --- a/pyconbalkan/news/models.py +++ b/pyconbalkan/news/models.py @@ -2,6 +2,7 @@ from django.utils import timezone from markdownx.models import MarkdownxField from taggit.managers import TaggableManager +from django.utils.text import slugify from pyconbalkan.conference.models import AbstractConference from pyconbalkan.core.models import ActiveModel @@ -17,6 +18,11 @@ class Post(ActiveModel, AbstractConference): image = models.ImageField(upload_to='posts/image') slug = models.CharField(unique=True, blank=True, max_length=100) + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(self.title) + super(Post, self).save(*args, **kwargs) + def publish(self): self.published_date = timezone.now() self.save()