The most efficient way to get user with userprofile in Django

In Django, in the recommended configuration, the UserProfile instance is associated with OneToOneField with the User instance.

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    data = ...

What is the most effective way to view both user and profile views? Is it possible to make a select_related () query on an inner join to get both objects with a single database hit? Or does it always boil down to two separate challenges? Perhaps Django auth middleware retrieves a user instance before invoking the view ... does anyone know?

+5
source share
1 answer
+1

All Articles