我正在使用django 1.7,我希望以有条件的方式让我们成为一个Count。这可以在django 1.8开始,但我无法升级。因此,我正在尝试编写this question.中详述的原始查询。遗憾的是,我还没有成功。
我的查询:
a = Photo.objects.raw(
'select "photos_photo"."id" , '
'COUNT('
'DISTINCT '
'CASE '
'WHEN "point_substanceexistslabel"."substance"."name" = "fabric" then 1 else null end) as c '
'FROM "photos_photo" '
'LEFT OUTER JOIN "points_substanceexistslabel" '
'on ("photos_photo"."id" = "points_substanceexistslabel"."photo_id")'
' GROUP BY "photos_photo"."id"'
)
运行查询并尝试打印结果会引发以下错误:
ProgrammingError: schema "point_substanceexistslabel" does not exist