Django User Profiles Deprecated

March 14, 2015

Django user profiles are deprecated in Django 1.6, but I have a legacy application that still needs to work with them. This post documents the steps used to remove this functionality, but still have the site work without making any database changes.

Change Profile Model

My existing model was:

user = models.ForeignKey(User, unique=True)

Changing this to:

user = models.OneToOneField(User, related_name="profile")

means that everything still works (and the data model is the same) yet there is an implicit .profile attribute available on the User model.

At this point you should be able to test the site and it should still be working exactly the same as before.

All that remains to be done is to change all references to get_profile() method to use profile attribute instead.

Replace get_profile() calls in code

The next stage is to do a global search and replace in your application code to change calls for .get_profile(). into just .profile.

Replace get_profile calls in templates

We now need to do the same with templates, so do another global search and replace in your application code and change calls .get_profile. to just .profile..

Again, at this point you should be able to test again and all code should behave the same as before.

Remove AUTH_PROFILE_MODULE

The final stage is to remove the AUTH_PROFILE_MODULE entry from settings.py

AUTH_PROFILE_MODULE='users.userprofile'

References