Issue #12 open

Why no name/slug?

yeago
created an issue

Hey,

Interested in adding the whole name = models.CharField, slug=models.SomeCharField to this project?

Might be nice to have a common home for that slugify snippet to live. Makes it into most of my projects.

Comments (4)

  1. mpontus

    Does it work with unicode? I would look at unidecode approach if you'd like to touch this issue: http://stackoverflow.com/a/4036665/326574

    Another pattern I commonly use is random slug for models which don't have appropriate field to slugify by, but I would like not to expose real auto increment value. I usually set it to base62 of random big integer, though it's open for debate whether it would be better performance-wise to store real integer and perform encoding at manager layer.

    Thanks for your effort, it would be great to see those patterns standantarized.

  2. Carl Meyer repo owner

    Hey yeago - sorry I never got back to you on this! I think something must have been wrong with BB email notifications or something, I never got an email.

    In an ideal world, I'd prefer an implementation of this that was encapsulated entirely in a SlugField-subclass, where you'd pass in the name of the name/title field you want it to read from (and it could automatically base its length on that, etc), rather than having an abstract Model that then dictates the "name" field, the max length, etc. This makes the whole "hooking into save()" aspect a bit trickier to implement, as you have to use the pre-save hook method on the field rather than just overriding save, but I'm pretty sure it's doable. Then things like self.SLUG_MAX_RETRIES can become arguments to the field as well rather than living on the model.

    Also, I'd like to have test coverage of the "too many failures, just re-raise" case, too.

    Re mpontus comment, I'm fine with delegating the default slugification to Django's slugify function, though it'd be great if you could pass a "slugify" callable to the field as another option, if you want to implement smarter slugification (e.g. using unidecode, which is excellent).

  3. Log in to comment