In Django, on a recommended setup, a UserProfile instance is linked by a OneToOneField with its User instance.
class UserProfile(models.Model):
user = models.OneToOneField(User)
data = ...
What is the most efficient way inside a view for retrieving both, user and profile? Can I do a select_related() inner join query, to get both objects with one database hit? Or does it always come down to two separate calls? Possibly, Django's auth middleware retrieves the user instance even before the view is called ... does anybody know?
The user profile can be retrieved using get_profile()
.
See documentation: https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With