繁体   English   中英

Django 1.3:升级后用户配置文件出现问题

[英]Django 1.3: Problems with UserProfile after upgrade

升级到 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 model 是这样指定的:

AUTH_PROFILE_MODULE = 'emailuser.UserProfile'

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

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

如果您尝试从用户 object 访问配置文件 model 不是正确的表示法:

user.get_profile()

UserProfile model 应该是与用户 model 的反向 FK 关系,因此不能作为属性使用。

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

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

事实证明,这是一个已知的 Django 错误,仅在您的代码中导入 UserAdmin 时才会出现。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM