2π
I think You should use User. UserProfile should be custom and can differ on each project. So if you will use same code for another project you can probably fail because of that. Also it is always easy to get user object in code and from that you have no problems to get profile user.get_profile()
as you show (and profile is not always needed). So ingeneral I think it will be easier to use other modules and passing them just user object (or id) and not the profile.
What is also could be the solution β write your own class which will be responsible for the users. Just write methods to return profile, return stuff_needed or whatever you want and everything just by passing user object and additional parameters about what you want.
So in short, Iβm for using User for Foreign keys, because in my opinion it just more logical, while the User model is always the main one (you always have it) and UserProfile is just extension.
Ignas
1π
If you just want all the goals belonging to a specific user add a foreign key to User in your Goal model.
class Goal(models.Model):
user = models.ForeignKey(User)
def myview(request):
goals = Goal.objects.filter(user=request.user)
Or alternately save all the goals for a user on your UserProfile model and do
def myview(request):
user_profile = user.get_profile()
goals = user_profile.goals
β¦or use a method to do processing to calculate them
goals = user_profile.calculate_goals()
- [Django]-FutureWarning: `TemplateForHostMiddleware` is deprecated. Please upgrade to the template loader
- [Django]-Gunicorn not running can't connect to sock file
- [Django]-While saving a Django model instance, in what order are my clean() and save() overrides applied relative to methods used as ModelField attributes?
- [Django]-Difference Between Reset Done and reset Complete in Django 2.0 Authentication Views
0π
Iβve been pondering the same thing myself for one of my sites but i decided to use UserProfile rather than User.
Not sure if its the right decision but it just seems more flexible.
- [Django]-Use get_object_or_404() method with mongoengine
- [Django]-How to save Django "forms.ModelForm" in database after editing it content and passing a javascript variable to it's new entered field