Wednesday, January 25, 2017

Re: Extended user model to add Profile class want to slugify first_name last_name in profile class

On Wednesday 25 January 2017 03:50:12 David wrote:

 

> I have extended Django's default user model to add a Profile model;

> bio etc.

>

> I want to slugify the users first_name last_name in profile class, so

> I can search for all X entities written by a specific user in the url

> form:

>

> /blog/authors/bob-smith

 

Strike the idea to give admin control over the slug. Instead, use django-autoslug and make the field not editable. Let autoslug handle conflicts by using sane values for populate_from and unique_with.

 

Example (from the docs):

# autoslugify value from a custom callable

# (ex. usage: user profile models)
slug = AutoSlugField(populate_from=lambda instance: instance.user.get_full_name())

Which is basically what you try to accomplish in the admin.

--

Melvyn Sopacua

No comments:

Post a Comment