[Answered ]-Django โ€“ how to query user profile based on User model having OneToOneField

2๐Ÿ‘

โœ…

You can get the User and use its UserProfile like so:

# Make sure you create a UserProfile when you create a new User
user = User.objects.get(email='example@examplemail.com')
user.userprofile.company_name
user.userprofile.country

Yes, this is a recommended way to add extra fields to the default django User model. See this question. If you are using your own User model you could just add the UserProfile fields to the User model.

๐Ÿ‘คikkuh

Leave a comment