1

I recently asked how to solve a simple SQL query. Turns out that there are many solutions.

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.

Community
  • 1
  • 1
santiagobasulto
  • 11,320
  • 11
  • 64
  • 88

1 Answers1

2

If you need exactly this query you can execute this in django like raw sql. Here 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 here

Aldarund
  • 17,312
  • 5
  • 73
  • 104