I'm using django 1.7, and I wish to make us a Count with a conditional. This is possible in django 1.8 onwards, but I'm unable to upgrade. As such, I'm trying to write a raw query as detailed in this question.. Regretfully, I haven't yet managed.
My query:
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"'
)
Running the query and trying to print a result raised the following error:
ProgrammingError: schema "point_substanceexistslabel" does not exist