Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slugs #155

Merged
merged 3 commits into from
Mar 21, 2019
Merged

Slugs #155

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyconbalkan/coc/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
6 changes: 6 additions & 0 deletions pyconbalkan/news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down