Extend Django User Model

Django CMS has its own User model but you might need to add attributes and other properties to it (like an avatar, right ?). The easiest way to do that is to extend that model with another model (we’ll call it UserProfile) and link them together using a one-to-one relationship.

Creating the UserProfile model

Nothing special here, I’m sure you know how it works.

Creating a UserProfile when creating a User

Each User needs to have a UserProfile object. To make sure that applies to every user, we’ll create a UserProfile each time a User is created. To do that. we’ll use the post_save signal (signals doc).

Just under the UserProfile code, you can add that code

And you’re pretty much good to go. You can access the user’s UserProfile using user.user_profile.

Published by

Louwii

Web developer, geek, car enthusiast, photographer, DIYer, video gamer... I like many things, maybe too many?

Leave a Reply

Your email address will not be published. Required fields are marked *