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

Adding slug convert option #572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions docs/getting_started.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ And then to any model you want tagging on do the following::
If you want ``django-taggit`` to be **CASE INSENSITIVE** when looking up existing tags, you'll have to set to ``True`` the TAGGIT_CASE_INSENSITIVE setting (by default ``False``)::

TAGGIT_CASE_INSENSITIVE = True

.. note::

If you want ``django-taggit`` to be convert to slug **RAW UNICODE** when saving tags, you'll have to set to ``True`` the TAGGIT_NATIVE_UNICODE_SLUG setting (by default ``False``)::

TAGGIT_NATIVE_UNICODE_SLUG = False (Default)

>> 'seoul'

TAGGIT_NATIVE_UNICODE_SLUG = True

>> '서울'
5 changes: 4 additions & 1 deletion taggit/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import IntegrityError, models, router, transaction
Expand Down Expand Up @@ -68,7 +69,9 @@ def save(self, *args, **kwargs):
return super(TagBase, self).save(*args, **kwargs)

def slugify(self, tag, i=None):
slug = slugify(unidecode(tag))
use_native_slug = getattr(settings, 'TAGGIT_NATIVE_UNICODE_SLUG', False)
slug = slugify(tag, allow_unicode=True) if use_native_slug else slugify(unidecode(tag))

if i is not None:
slug += "_%d" % i
return slug
Expand Down