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 Extending the User model with custom fields in Django with no luck.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.