mozilla / unicode-slugify

A slugifier that works in unicode
BSD 3-Clause "New" or "Revised" License
321 stars 52 forks source link

UnicodeSlugField for Django #10

Closed mathiasose closed 8 years ago

mathiasose commented 10 years ago

I thought others might encounter the same problem as I did, so I'll share my solution and possibly get some feedback if there is a better way to do it.

Problem: If you use slugs generated by unicode-slugify with Django's SlugField, you will be prevented from saving a form with a SlugField (e.g. in the Django Admin) if the field value is invalid by Django's slug standard.

Solution: Replace SlugField with a new UnicodeSlugField which inherits everything from SlugField except that pesky validation. Add a new validator using unicode-slugify.

mathiasose commented 8 years ago

Since 1.9 Django supports unicode slugs and SlugFields natively.

https://docs.djangoproject.com/en/1.9/ref/utils/#django.utils.text.slugify https://docs.djangoproject.com/en/1.9/ref/models/fields/#slugfield