From ecc28bf315079c809daa2f1e7dfadcfd5059df44 Mon Sep 17 00:00:00 2001 From: "hyunwoo.shim" Date: Mon, 10 Dec 2018 22:08:24 +0900 Subject: [PATCH] Add slug convert option TAGGIT_NATIVE_UNICODE_SLUG --- docs/getting_started.txt | 12 ++++++++++++ taggit/models.py | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/getting_started.txt b/docs/getting_started.txt index e7a7e0e4..4d137e5b 100644 --- a/docs/getting_started.txt +++ b/docs/getting_started.txt @@ -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 + + >> '서울' diff --git a/taggit/models.py b/taggit/models.py index a969f842..517b9308 100644 --- a/taggit/models.py +++ b/taggit/models.py @@ -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 @@ -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