开发者

Django 1.3: Problems with UserProfile after upgrade

开发者 https://www.devze.com 2023-03-19 15:13 出处:网络
After an upgrade to Django 1.3 (from 1.2.3) the following row causes a crash: users = self.users.filter(userprofile__public_profile=True).order_by(\'first_name\')

After an upgrade to Django 1.3 (from 1.2.3) the following row causes a crash:

users = self.users.filter(userprofile__public_profile=True).order_by('first_name')

The error shown:

Caught FieldError while rendering: Cannot resolve keyword 'userprofile' into field. Choices are: _message_set, comment, commentabusereport, date_joined, dialog, dialogabusereport, email, first_name, forums, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, password, registrationprofile, user_permissions, u开发者_如何学Goserassociation, username, vote

Just as before, the UserProfile model is specified like this:

AUTH_PROFILE_MODULE = 'emailuser.UserProfile'

Funny thing, some of the fields displayed as availible (such as "dialogabusereport" and "userassociation") are in turn other internal models with the same kind of user relation as the one from UserProfile.

Any ideas of what may cause this? Why can Django no longer see our UserProfile model in this relation?


If you are trying to access the profile model from a user object isn't the correct notation:

user.get_profile()

The UserProfile model should be a reverse FK relation to the User model and so is not available as an attribute.

If you wanted to find all the UserProfile objects where userprofile = True ordered by the first_name field it would be:

userprofiles = UserProfile.objects.filter(public_profile=True).order_by('user__first_name')


As it turns out, this is a known Django bug only casued when importing UserAdmin in your code.

https://code.djangoproject.com/ticket/15771

0

精彩评论

暂无评论...
验证码 换一张
取 消