Hello,

I'm using a solution I saw on a RoR blog (http://
blog.hasmanythrough.com/2006/7/7/more-on-naming-and-the-crud has a
summary of the technique) which should address the 'reversibility'
issue. Basically you just concatenate the object id with the slug of
the human readable name, but then just ignore everything but the
object id in your urlpatterns. First, you'd change your model like so:

def get_absolute_url(self):
    return "/characters/%s/" % self.id + '-' + (slugify(self.name))

This will generate urls like "/characters/123-bob-and-jane".
Next, change your urls.py like so:

(r'^characters/(?P<id>\d+)[-\w]+/$', object_detail,
dict(character_detail_dict)),

This should capture the '123' and discard '-bob-and-jane'. This is a
fairly elegant solution that allows you to still have 'pretty' urls
that are human readable and google friendly while completely
sidestepping the complications of record retrieval based on reverse
engineering slugs or bothering with a slug column, opting instead for
the dead-simple and fast id lookup.

Hope this helps.

Btw, I assume you're just importing the slugify method from
django.template.defaultfilters? This is what I did, rather than write
my own method.

Cheers,
John-Scott

(note: I tried writing this response a few hours ago, but it doesn't
appear to have posted correctly. If it magically appears, I'll remove
the duplicate post)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to