views:

109

answers:

1

I am trying to extend the User model so that I can add my own custom fields but I keep getting an error stating:

'NoneType' object has no attribute '_default_manager'

whenever I try to use

user.get_profile()

to add values to the custom field i.e. whenever I use it like so:

user = User.objects.create_user(username, email, password)

user.first_name = fname

user.last_name = lname

user.save()

uinfo = user.get_profile()

uinfo.timezone = "Asia/Pune"

uinfo.save()

I have already followed the steps given at http://stackoverflow.com/questions/44109/extending-the-user-model-with-custom-fields-in-django/965883#965883 with no luck.

+2  A: 

First of all: are you absolutely sure that you put the correct value for AUTH_PROFILE_MODULE in your settings.py file? Because the exception should look different if there was no UserProfile for this user. (DoesNotExist)

Anyway: there is no UserProfile object at that time, because it is not generated automatically. So get_profile() raises an exception in your case.

Either do this:

if not UserProfile.objects.filter(user=user):
    p = UserProfile(user=user)
    p.save()
uinfo = user.get_profile()
...

or create a signal as (loosely) described at http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

mawimawi