random ramblings and various other shenanigans

› Extending Djangos auth.User

I was trying to find a good way to extend the User model from django.contrib.auth which seemed as easy as


from django.contrib.auth.models Import User
class User(User):
photo_url = models.CharField(blank=True,max_length=200)

Seemed easy enough, and looking at the sql that was produced it looked like I'd guessed correctly.

However when trying to use this model on the admin site I was running into error after error and eventually ran into the article Tips on Extending User model which explains that this is the wrong way to go.

To sumarise, create a User or UserProfile model which references auth.User


from django.contrib.auth.models import User
class User(models.Model):
photo_url = models.CharField(blank=True,max_length=200)
user = models.ForeignKey(User, unique=True)

Add this to settings.py


AUTH_PROFILE_MODULE = 'myapp.User'

and you can reference the variables with


u = User.objects.get(pk=1)
u.get_profile().photo_url

by Ben on 14:56, August 19, 2007

Add to:



There are currently no comments for this item

Leave comment:

Your Name:

Comments: