Django: how to properly use UserProfile? (Django auth extra information)
i finally can make my Django+Auth app works. I add the extra information to the user as the docs say开发者_开发知识库. Now, i've a simple question. When i'm building a model that is related to the user, which user should i relate to? To auth.models.User or to my accounts.UserProfile?
An example: I've a model for Product, and the Product belongs to a user. Which would be the best option:
class Product(models.Model):
user = models.ForeignKey(auth.models.User)
or
class Product(models.Model):
user = models.ForeignKey(accounts.UserProfile)
I'm currently using auth.models.User, becouse i can issue a get_profile, but some friend told me that i was wrong.
Thank you!
You're doing the right thing.
UserProfile is just an extension of the User model. And logically you're making a relation of a object with an object, not a relation of a object with some extra information.
Also, as you mentioned, you can always issue the 'get_profile' to get the extra data.
精彩评论