Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I ForeignKey to Django User or a Profile model?

I'm wondering what people's thoughts are on joining models directly to the auth.User object vs to the user's profile model.

I'm storing some different types of models which my user are adding in my app. App users will search for other users via criteria on these models.

On the one hand, I'm thinking that if I join straight to User then I won't need to do request.user.get_profile() each time I need to grab the User's records, and it doesn't presuppose that a User always has a profile (they do in my app at the mo, but still). This leaves the profile model as just containing the user's contact details.

On the other hand, I imagine I'll most likely need values from the Profile (eg name, location) when I'm looking up these other models.

No doubt either will work, so maybe it doesn't matter, but I just wondered what other people's thoughts were.

Thanks!

Ludo.

like image 383
Ludo Avatar asked Oct 26 '11 11:10

Ludo


1 Answers

I would also recommend creating foreign-keys to the User model. It just makes your life simpler when working with the user object in the view, for one. So, you can do things like request.user.foo_set, etc. without having to go through the profile model.

like image 166
Shailen Tuli Avatar answered Oct 24 '22 17:10

Shailen Tuli