django-userprofiles icon indicating copy to clipboard operation
django-userprofiles copied to clipboard

Django 1.5 AttributeError at /userprofiles/change/ 'NoneType' object has no attribute 'objects'

Open chrisfranklin opened this issue 12 years ago • 6 comments

Does the contrib package still work with Django 1.5, I seem to be getting this error:

 /home/chris/.virtualenvs/farm/local/lib/python2.7/site-packages/django/views/generic/edit.py in get_form

            return form_class(**self.get_form_kwargs())

    ...

▼ Local vars
Variable    Value
self    

<userprofiles.contrib.profiles.views.ProfileChangeView object at 0x7fb1ac304350>

form_class  

<class 'userprofiles.contrib.profiles.forms.ProfileForm'>

/home/chris/.virtualenvs/farm/local/lib/python2.7/site-packages/userprofiles/contrib/profiles/views.py in get_form_kwargs

            kwargs['instance'] = get_profile_model().objects.get(

    ...

▼ Local vars
Variable    Value
self    

<userprofiles.contrib.profiles.views.ProfileChangeView object at 0x7fb1ac304350>

kwargs  

{'initial': {}}

chrisfranklin avatar Mar 28 '13 22:03 chrisfranklin

Are you using the the latest version of django-userprofiles? If yes, can you provide a code example which raises the error?

stephrdev avatar Apr 08 '13 11:04 stephrdev

Hey,

Thanks for getting back to me, I am not at home right now but I will have a proper look at this towards the end of the week. Sorry it is not sooner.

All the best,

Chris

chrisfranklin avatar Apr 08 '13 12:04 chrisfranklin

Did you have a chance to prepare a example to reproduce the error? As I can't find a way to get the error, I'll close the issue within the next days.

stephrdev avatar Jun 16 '13 11:06 stephrdev

i am seeing same issue, using latest repository. the problem line is https://github.com/stephrdev/django-userprofiles/blob/master/userprofiles/contrib/profiles/views.py#L29 and get_profile_model() is returning null

all i've done is enable userprofiles.contrib.profiles in INSTALLED_APPS and browsed to /profile/change

kn0ll avatar Jun 27 '13 08:06 kn0ll

the error exists because get_profile_model() returns None unless USE_PROFILE = True, which by default is False. i've fixed this by simply adding the following to my settings:

AUTH_PROFILE_MODULE = 'auth.User'
USERPROFILES_USE_PROFILE = True

this is followed by another error: Cannot resolve keyword 'user' into field. Choices are: date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password, user_permissions, username. this comes from https://github.com/stephrdev/django-userprofiles/blob/master/userprofiles/contrib/profiles/views.py#L30.

i resolved this by changing user=self.request.user to id=self.request.user.id. admittedly i'm new to Python and Django so i'm not confident at all this is the proper fix.

kn0ll avatar Jun 27 '13 08:06 kn0ll

Thanks. I'm going to write a patch for that.

MarkusH avatar Jun 27 '13 10:06 MarkusH