Perfect example! On Feb 18, 2010, at 4:09 PM, Matt McCants wrote:
> Here's a stripped down example. I've messed with using signals instead > of overriding the save method for all the models that need a slug. But > this is quick and easy. > > http://gist.github.com/308068 > > Matt > > On Thu, 2010-02-18 at 14:53 -0600, Jon Loeliger wrote: >>> >>>> Is there a canonical definition or even a reference implementation >>>> of a slug =3D slugify(str) function somewhere? Yeah, I could go >>>> grep through the sources and maybe find one? And yes, I see: >>>> =20 >>>> http://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield >>>> =20 >>>> But even that is a bit ambiguous as to the treatment of underscores. >>> >>> Could you clarify what you mean by "ambiguous as to the treatment of unders= >>> cores"? I don't see an ambiguity, so I wonder what I'm missing. >> >> Some places say underscores are valid, others say they removed: >> >> http://docs.djangoproject.com/en/dev/ref/templates/builtins/ >> >> slugify >> >> Converts to lowercase, removes non-word characters >> (alphanumerics and underscores) and converts spaces to >> hyphens. Also strips leading and trailing whitespace. >> >> >>> My understanding is that a slug is usable as a URL; that's really the synta= >>> x definition, and is why it is limited to "only letters, numbers, underscor= >>> es or hyphens." A slug is effectively an artifact of Django's birth in jour= >>> nalism-on-the-web, and an extraordinarily handy one. As such, it exists fo= >>> r practical reasons, rather than purity. >> >> Sure, I get that. >> >> It would be nice to use the same (or at least internally consistent) >> definition, of course. >> >>> I do indeed use the slugify() function for precisely that pattern. >> >> Exactly *which* slugify() function? Documentation reference? >> Import from line? >> >>> I override the model's save method, and populate the slug field prior >>> to allowing the save to proceed. I picked up that trick from some >>> other code somewhere; it isn't uncommon. >> >> Well, yeah. That's what I want to do too! :-) Any chance you >> can post a snippet for me? >> >>> HTH, >> >> Somewhat! >> >> Thanks, >> jdl >> > > > > This message is confidential, intended only for the named recipient(s) and > may contain information that is privileged or exempt from disclosure under > law. If you are not the intended recipient(s), you are notified that the > dissemination, distribution, or copying of this message is strictly > prohibited, and that this message should be deleted from your system. The > Free Lance-Star Publishing Company accepts no liability for the content of > this message, or for the consequences of any actions taken on the basis of > the information provided. If you receive this message in error, or are not > the named recipient(s), please notify the sender and delete the document from > your computer. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.