class Profile User jabberID models CharField JabberID max_length 255 b

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Profile(User):
jabberID = models.CharField(_('JabberID'), max_length=255, blank=True, null=True)
objects = UserManager()
def __unicode__(self):
return smart_unicode(u"%s's profile" % self.username)
class Admin:
pass
class Test(models.Model):
profile = models.ForeignKey(Profile)
test = models.CharField(max_length=255)
In [22]: t_qs = Test.objects.select_related()
In [23]: connection.queries
Out[23]: []
In [24]: t_qs
Out[24]: [<Test: Test object>]
In [25]: connection.queries
Out[25]:
[{'sql': 'SELECT "accounts_test"."id", "accounts_test"."profile_id", "accounts_test"."test", "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined", "accounts_profile"."user_ptr_id", "accounts_profile"."jabberID" FROM "accounts_test" INNER JOIN "accounts_profile" ON ("accounts_test"."profile_id" = "accounts_profile"."user_ptr_id") INNER JOIN "auth_user" ON ("accounts_profile"."user_ptr_id" = "auth_user"."id")',
'time': '0.001'}]
In [28]: for t in t_qs:
....: t.profile.username
....:
....:
Out[28]: u'root'
In [29]: connection.queries
Out[29]:
[{'sql': 'SELECT "accounts_test"."id", "accounts_test"."profile_id", "accounts_test"."test", "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined", "accounts_profile"."user_ptr_id", "accounts_profile"."jabberID" FROM "accounts_test" INNER JOIN "accounts_profile" ON ("accounts_test"."profile_id" = "accounts_profile"."user_ptr_id") INNER JOIN "auth_user" ON ("accounts_profile"."user_ptr_id" = "auth_user"."id")',
'time': '0.001'},
{'sql': 'SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined", "accounts_profile"."user_ptr_id", "accounts_profile"."jabberID" FROM "accounts_profile" INNER JOIN "auth_user" ON ("accounts_profile"."user_ptr_id" = "auth_user"."id") WHERE "accounts_profile"."user_ptr_id" = 1 ',
'time': '0.001'}]