[Django]-Django. Non-ascii field doesn't create slug. I expect to get transliteration, but getting an empty field and error

2👍

I found the solution!

Thanks to KenWhitesell https://forum.djangoproject.com/t/django-slugify-error/6153/4 and Evgeny https://stackoverflow.com/a/4036665/15109119

It is also possible to use javascript, for example, as is used to auto populate the slug-field in the Django admin panel. It needs to use ‘allow_unicode=True’ while actually ‘slugifying’ the field.

def save(self, *args, **kwargs):
    if not self.slug:
        self.slug = slugify(self.title, allow_unicode=True)
    return super().save(*args, **kwargs)

Leave a comment