Closed gnotaras closed 10 years ago
Just noticed that django has all the required code to easily implement this:
settings.py
TAGGIT_DEFAULT_SLUGIFY_FUNCTION = 'django.template.defaultfilters.slugify'
models.py
from django.core.urlresolvers import get_callable
from taggit import settings # Or wherever you keep the defaults
default_slugify = get_callable(settings.TAGGIT_DEFAULT_SLUGIFY_FUNCTION)
Good idea George, currently it's kind of hassle to go through all the proxy/subclass stuff.
+1 for this change. Currently, if you try and tag an object with different cases (i.e. "Hello" and "hello"), it uses an "_#" as the separater which gives you a url that looks like:
/tags/hello
and
/tags/hello_1
Tags with underscores, IMHO, are quite ugly and are not a recommended best practice by google [1]:
We recommend that you use hyphens (-) instead of underscores (_) in your URLs.
Instead if would be great to define the slugifier method as mentioned above or change the models slugify method to instead be:
def slugify(self, tag, i=None):
slug = default_slugify(tag)
if i is not None:
slug += "-%d" % i
return slug
[1] https://support.google.com/webmasters/answer/76329?hl=en
In my fork https://github.com/alex/django-taggit/pull/188 you can define slugify function via setting AUTOSLUG_SLUGIFY_FUNCTION = '...'
Closing in favor of #188
The slugify filter of django is very poor when it deals with languages other than English. On the other hand, there is much work involved in order to override the default Tag.slugify() method in your app.
It would be a lot more convenient if we could set the default slugify function using a setting, eg:
Moreover, it would be perfect if you used the unidecode module by default instead of the poor django filter, which is only useful for English.
Thanks.