Add utf-8 support in slugs with autoslug
Slugs end up empty if list name consists only of non-ascii characters and that results in an error. Autoslug converts non-ascii characters to appropriate ascii ones and auto-updates the slug when list name changes. Add unidecode dependency and fix PEP8 errors models.py: add one blank line for PEP8
This commit is contained in:
parent
f235b4effc
commit
710cb1a0ad
2 changed files with 3 additions and 8 deletions
1
setup.py
1
setup.py
|
@ -99,6 +99,7 @@ setup(
|
|||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
tests_require=['tox'],
|
||||
install_requires=['django-autoslug', 'unidecode', ],
|
||||
cmdclass={
|
||||
'clean': Clean,
|
||||
'test': Tox,
|
||||
|
|
|
@ -3,24 +3,18 @@ import datetime
|
|||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import Group
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.conf import settings
|
||||
from autoslug import AutoSlugField
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class List(models.Model):
|
||||
name = models.CharField(max_length=60)
|
||||
slug = models.SlugField(max_length=60, editable=False)
|
||||
slug = AutoSlugField(populate_from='name', editable=False, always_update=True)
|
||||
group = models.ForeignKey(Group)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.id:
|
||||
self.slug = slugify(self.name)
|
||||
|
||||
super(List, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
|
Loading…
Reference in a new issue