Automatically create django User Profiles as needed.

Ran across a very nice, brief run down of creating user profiles for django on Turnkey Linux.

I was particularly pleased of this "ism" that creates user profiles on the fly on an as needed basis. As a bonus, it provides access to the profiles through a user.profile property. All you have to do is place the following property declaration at the bottom of your profile's

User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

And that's it. Now, when someuser.profile is called, it'll create a default profile if needed or return that user's profile if it exists. See the original article for a full User Profile quickstart.

Share on: TwitterFacebookGoogle+Email

Comments !