Disabling allow_unicode in djangot-taggit without modifying the module

35 views Asked by At

I'm using django-taggit and I have a problem that polish symbols like ś, ć, ę... appear in slugs of tags.

I want slugs to be ASCII only.

Using TAGGIT_STRIP_UNICODE_WHEN_SLUGIFYING = True solves the problem partially. When creating tags they actually change unwanted characters as this: ś -> s but when I create tag in admin, slug gets automatically prepopulated without striping/changing the characters. I would like it to do so.

As far only solution I found is modifying source of django-taggit as follows:

class TagBase(models.Model):
    name = models.CharField(
        verbose_name=pgettext_lazy("A tag name", "name"), unique=True, max_length=100
    )
    slug = models.SlugField(
        verbose_name=pgettext_lazy("A tag slug", "slug"),
        unique=True,
        max_length=100,
        allow_unicode=False,
    )

Precisely allow_unicode=False

I was also considering unregistering TagAdmin and switching it to my own.

Is there any clean solution that doesn't require modifying django-taggit module?

0

There are 0 answers