Cannot get user profile working.

219 views
Skip to first unread message

Alex

unread,
Sep 1, 2008, 8:22:05 PM9/1/08
to Django users
I have a user profile defined in web.core.models.py and I cannot get
this to work at all. I am constantly getting the following:

>>> User.objects.get(username="Alex")
<User: alex>
>>> User.objects.get(username="Alex").get_profile()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Program Files\Python25\lib\site-packages\django\contrib\auth
\models.py", line 294, in get_profile
self._profile_cache =
model._default_manager.get(user__id__exact=self.id)
AttributeError: 'NoneType' object has no attribute '_default_manager'

I have set the following in settings.py (among a thousand other
combinations).

AUTH_PROFILE_MODULE = "web.webuserprofile"

I have also tried:

AUTH_PROFILE_MODULE = "web.core.webuserprofile" which gives me Too
Many Values to Unpack.

I have also tried to create a simple models.py that import
core.webuserprofile.models.py but that didn't work either.

Can someone please help me. This has cost me an unbelievable amount
of time trying to get this going.

James Bennett

unread,
Sep 1, 2008, 8:29:27 PM9/1/08
to django...@googlegroups.com
On Mon, Sep 1, 2008 at 7:22 PM, Alex <al...@gierus.ca> wrote:
> I have set the following in settings.py (among a thousand other
> combinations).

The value you want is the app label, which is 'core', followed by a
dot, followed by the model name, which is 'userprofile'. So
'core.userprofile'. Not 'web.core.userprofile', not 'web.userprofile',
not anything with "web" in it.


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Alex

unread,
Sep 2, 2008, 10:13:53 AM9/2/08
to Django users
Thanks, worked perfectly.

Not sure if it's just me and my lack of sleep or the docs aren't that
clear on this item. I didn't see much regarding this on the Internet
so there must not be scores of others making the same mistake.

kylewild

unread,
Oct 24, 2008, 3:23:14 PM10/24/08
to Django users
I'm having this same issue and the fix here, as best I can attempt to
apply it, didn't work for me

I had AUTH_PROFILE_MODULE set to "myproject.UserProfile"

After reading this thread, I changed it to "chat.UserProfile" -- to no
avail


In my "chat" directory, I have the model "UserProfile" defined in
models.py -- doesn't that mean "chat" is the name of the app?

Brian Neal

unread,
Oct 24, 2008, 3:54:57 PM10/24/08
to Django users
On Oct 24, 2:23 pm, kylewild <k...@kylewild.com> wrote:
> I'm having this same issue and the fix here, as best I can attempt to
> apply it, didn't work for me
>
> I had AUTH_PROFILE_MODULE set to "myproject.UserProfile"
>
> After reading this thread, I changed it to "chat.UserProfile" -- to no
> avail
>
> In my "chat" directory, I have the model "UserProfile" defined in
> models.py -- doesn't that mean "chat" is the name of the app?
>

Read this:
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

I think you want all lower case.

kylewild

unread,
Oct 24, 2008, 4:01:16 PM10/24/08
to Django users
thanks brian, good call

I had read that and somehow not parsed it!


However, I'm still having the issue after changing it to:

AUTH_PROFILE_MODULE = 'chat.userprofile'

(i tried myproject.userprofile as well)



'NoneType' object has no attribute '_default_manager'
/home/mochat/webapps/django/lib/python2.5/django/contrib/auth/
models.py in get_profile, line 293
> Read this:http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-...

Brian Neal

unread,
Oct 24, 2008, 7:14:58 PM10/24/08
to Django users
On Oct 24, 3:01 pm, kylewild <k...@kylewild.com> wrote:
> thanks brian, good call
>
> I had read that and somehow not parsed it!
>
> However, I'm still having the issue after changing it to:
>
> AUTH_PROFILE_MODULE = 'chat.userprofile'
>
> (i tried myproject.userprofile as well)
>
> 'NoneType' object has no attribute '_default_manager'
> /home/mochat/webapps/django/lib/python2.5/django/contrib/auth/
> models.py in get_profile, line 293
>

We really need more info before anyone can even guess. Try posting
some code, including your model code and the call site where you are
calling .get_profile().

kylewild

unread,
Oct 24, 2008, 10:03:27 PM10/24/08
to Django users
here's the model:

from django.db import models
from django.contrib.auth.models import User


# this will set us up to use user.get_gender_display, thanks to
django's get_FOO_display
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)


# defining the model for UserProfile, which extends Django's "User"
model and can be fetched using user.get_profile()
class UserProfile(models.Model):
phone_number = models.PhoneNumberField()
description = models.TextField()
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
age = models.IntegerField()
user = models.ForeignKey(User, unique=True)






and here's the view with relevant imports:

from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required



@login_required
def chatrooms(request):
u = User.objects.get(pk=1) # Get the first user
user_address = u.get_profile().phone_number # fetch user's phone
number from the db
return render_to_response('chat/chatrooms.html',
{'user_address': user_address})
Reply all
Reply to author
Forward
0 new messages