Django: realizar una coincidencia de SQL en Django

Recientemente pregunté how to solve a simple SQL query. Turns out that there are muchas soluciones.

After some benchmarking i think this is the best one:

SELECT DISTINCT Camera.*
FROM Camera c
     INNER JOIN cameras_features fc1 ON c.id = fc1.camera_id AND fc1.feature_id = 1
     INNER JOIN cameras_features fc2 ON c.id = fc2.camera_id AND fc2.feature_id = 2

Now, I've not clue how to perform this query with Django ORM.

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

If you need exactly this query you can execute this in django like raw sql. Aquí you can find about raw sql in django.

It`s good to put your sql code into a custom manager. An example with manager and raw sql can be found aquí

Respondido 02 Feb 12, 02:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.