![](/img/trans.png)
[英]How to use the same auth userprofile in multiple apps in Django 1.6
[英]Django: how to properly use UserProfile? (Django auth extra information)
我終於可以使我的Django + Auth應用程序正常工作了。 正如文檔所說,我向用戶添加了額外的信息。 現在,我有一個簡單的問題。 當我建立與用戶相關的模型時,我應該與哪個用戶相關? 要auth.models.User還是我的account.UserProfile?
一個例子:我有一個Product的模型,而Product屬於用戶。 最好的選擇是:
class Product(models.Model):
user = models.ForeignKey(auth.models.User)
要么
class Product(models.Model):
user = models.ForeignKey(accounts.UserProfile)
我當前正在使用auth.models.User,因為我可以發出get_profile,但是一些朋友告訴我我錯了。
謝謝!
你做對了。
UserProfile只是User模型的擴展。 從邏輯上講,您正在建立對象與對象的關系,而不是對象與某些額外信息的關系。
另外,正如您提到的,您始終可以發出“ get_profile”來獲取額外的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.