4

升级到 Django 1.3(从 1.2.3)后,以下行会导致崩溃:

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

显示的错误:

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, userassociation, username, vote

和以前一样,UserProfile 模型是这样指定的:

AUTH_PROFILE_MODULE = 'emailuser.UserProfile'

有趣的是,一些显示为可用的字段(例如“dialogabusereport”和“userassociation”)又是其他内部模型,它们与 UserProfile 中的用户关系类型相同。

关于可能导致这种情况的任何想法?为什么 Django 在这个关系中看不到我们的 UserProfile 模型?

4

2 回答 2

1

如果您尝试从用户对象访问配置文件模型不是正确的表示法:

user.get_profile()

UserProfile 模型应该是与 User 模型的反向 FK 关系,因此不能用作属性。

如果您想查找 userprofile = True 由 first_name 字段排序的所有 UserProfile 对象,它将是:

userprofiles = UserProfile.objects.filter(public_profile=True).order_by('user__first_name')
于 2011-09-18T09:22:15.107 回答
1

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

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

于 2011-09-19T06:52:12.990 回答