Thursday, August 30, 2018

Doubts on One-To-One Field

def userProfile(models.Model):
       Other stuff
I can query it like this 
x = userProfile.objects.get(user__id=1)(Assuming this exists)

when I do a connection.queries a single query is executed.When I try to access the username i.e x.user.username a new query is executed again when I see connection.queries? Is this the expected behavior. Wouldn't this be bad if we have huge databases? I have a scenario where some classes have common information and then they have different fields based on their classes. I have tested this OneToOneField by the above example and for some reason reluctant to use this because of the new query? The other approach would be abstract base classes where information stored in the db would be duplicated but the additional query can be saved I think any thoughts?

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment