2011-07-09 37 views
1

我已經延長通過AUTH_PROFILE_MODULEUser到包括ManyToMany場項目用戶參與。反向查詢擴展的用戶簡

我想扭轉的關係,並獲得與特定項目相關的用戶。

我的用戶有配置文件(我已成功地將它們返回related_projects = u.profile.projects)。

related_users = project.userprofile_set.all()正在給我東西 - {% for user in related_users %} {{ user }} {% endfor %}收益率User Profile for: richlyon。但我不能讓{{ user }}產生任何領域。我試過{{ user.username }}

問題:我正在以這種錯誤的方式進行?如果我不是,我如何從擴展的用戶配置文件中的反向關係中獲取字段信息?

非常感謝您的時間。

回答

1

您的'個人資料'對象不是User,也不是延伸User(以面向對象的意義)。相反,它是一個單獨的模型,其ForeignKeyUser

用戶>個人資料>項目

在您發佈的代碼,它看起來像你期待從project.userprofile_set.all()查詢集返回User對象。但是,這些將成爲您的中間配置文件對象,然後您可以訪問該用戶。

事情是這樣的:

related_profiles = project.userprofile_set.all() 

{% for profile in related_profiles %} 
    {{ profile.user.username }} 
{% endfor %} 
+0

...並感謝您的解釋和解決方案 - 這完美的作品。 – Richard