For all my foreign users should I use User or UserProfile in Django?

Here is a hit to remove.

I have both User and ProfileUser. I would like to add additional logic to the model, and since I cannot add it to the Django User model, I have to add it to ProfileUser. Currently, all my models have ForeignKey (User). Should I store them this way or should the user ForeignKey (UserProfile) on my other models?

An example for my view, if I save ForeignKey (User):

class myview(request):
    user = request.user
    userProfile = user.get_profile()
    neededStuff = userProfile.get_needed_stuff()

and then in the UserProfile model:

def get_needed_stuff(self):
    user= self.user # Or actually, is this right 
    goals = Goal.objects.get(<conditions that i wont bother writing here>)
    return goals

So, for this case and for the further development of the site, which should use a foreign key?

+3
source share
3 answers

, User. UserProfile . , , , , . , user.get_profile(), ( ). , ( id), .

- , . , , stuff_needed , , .

, User for Foreign keys, , , , User ( ), UserProfile - .

+2

, , , .

class Goal(models.Model):
    user = models.ForeignKey(User)

def myview(request):
    goals = Goal.objects.filter(user=request.user)

UserProfile

def myview(request):
    user_profile = user.get_profile()
    goals = user_profile.goals

...

goals = user_profile.calculate_goals()
+1

I thought the same thing for one of my sites, but decided to use UserProfile, not User. Not sure if this is the right solution, but it seems more flexible.

0
source

All Articles