ct ContentType objects get_for_model post return ThreadedComment tree

 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
#ct = ContentType.objects.get_for_model(post)
# return ThreadedComment.tree.filter(object_id=post.id, content_type=ct).select_related()
#generates this SQL
SELECT `comments`.`id`, `comments`.`content_type_id`, `comments`.`object_id`,
`comments`.`parent_id`, `comments`.`author_id`, `comments`.`date_submitted`,
`comments`.`date_modified`, `comments`.`date_approved`, `comments`.`comment`,
`comments`.`score`, `comments`.`is_public`, `comments`.`is_approved`,
`comments`.`ip_address`, `comments`.`lft`, `comments`.`rght`, `comments`.`tree_id`,
`comments`.`level`, `django_content_type`.`id`, `django_content_type`.`name`,
`django_content_type`.`app_label`, `django_content_type`.`model`, `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` FROM `comments` INNER JOIN `django_content_type` ON
(`comments`.`content_type_id` = `django_content_type`.`id`) INNER JOIN `auth_user` ON
(`comments`.`author_id` = `auth_user`.`id`) WHERE (`comments`.`object_id` = 3 AND
`comments`.`content_type_id` = 13 ) ORDER BY `comments`.`tree_id` ASC, `comments`.`lft`
ASC
#but i need this SQL, added db2 prefix
SELECT `comments`.`id`, `comments`.`content_type_id`, `comments`.`object_id`,
`comments`.`parent_id`, `comments`.`author_id`, `comments`.`date_submitted`,
`comments`.`date_modified`, `comments`.`date_approved`, `comments`.`comment`,
`comments`.`score`, `comments`.`is_public`, `comments`.`is_approved`,
`comments`.`ip_address`, `comments`.`lft`, `comments`.`rght`, `comments`.`tree_id`,
`comments`.`level`, `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` FROM `comments` INNER JOIN
`db2`.`auth_user` as `auth_user` ON (`comments`.`author_id` = `auth_user`.`id`) WHERE
(`comments`.`object_id` = 3 AND `comments`.`content_type_id` = 13 ) ORDER BY
`comments`.`tree_id` ASC, `comments`.`lft` ASC