On Feb 18, 2010, at 3:01 PM, Jon Loeliger wrote:

> Folks,
> 
> Quick question or two:
> 
> Is there a canonical definition or even a reference implementation
> of a slug = slugify(str) function somewhere?  Yeah, I could go
> grep through the sources and maybe find one?  And yes, I see:
> 
>    http://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield
> 
> 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 
underscores"?  I don't see an ambiguity, so I wonder what I'm missing.

My understanding is that a slug is usable as a URL; that's really the syntax 
definition, and is why it is limited to "only letters, numbers, underscores or 
hyphens." A slug is effectively an artifact of Django's birth in 
journalism-on-the-web, and an extraordinarily handy one.  As such, it exists 
for practical reasons, rather than purity.

> Naturally, I'm wanting to use a slug to identify some model instances
> based on some other model field.  But it's not being entered via the
> Admin model, so I can't do the prepopulated_fileds[] trick either.

I do indeed use the slugify() function for precisely that pattern.  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.

HTH,

---Peter Herndon

-- 
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.

Reply via email to