2011-07-11 45 views
4

之後升級到1.3的Django(從1.2.3)後,以下行會導致系統崩潰:的Django 1.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 

正如之前,該用戶配置模型指定這樣的:

AUTH_PROFILE_MODULE = 'emailuser.UserProfile' 

有趣的事情,某些字段顯示爲菱(如「對話框幷gabusereport「和」userassociation「)反過來是與UserProfile中的用戶關係具有相同用戶關係的其他內部模型。

任何可能導致這種情況的想法?爲什麼Django不能在這個關係中看到我們的UserProfile模型?

+0

有類似的問題,又回到Django的1.2.3和我的項目再次工作。希望我可以幫你解答 - 至少我可以爲你的問題投票。 – golliher

+0

您是否有機會從配置文件的應用程序models.py文件中的django.contrib.auth.admin導入UserAdmin?可能是由這個問題引起的:https://code.djangoproject.com/ticket/15771 –

回答

1

如果你正試圖從一個用戶對象訪問配置模式是不正確的符號:

user.get_profile() 

的用戶配置模式應該是相反的FK關係到用戶模式,所以是不能作爲屬性。

如果你想找到的所有用戶配置對象,其中USERPROFILE =真由FIRST_NAME字段排序這將是:

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