Skip to main content
100%

Django ORM subquery example

✓ Published0🌍 Public
Aandybak
Last edited Sep 15, 2014
Created on Sep 15, 2014

This example demonstrates how to translate a SQL query into Django’s ORM to filter consignments that are not linked to any booking with a “quote” status. It shows the equivalent raw SQL with nested subqueries and LEFT OUTER JOINs, alongside the Python code using `Consignment.objects.filter()` with `Q` objects and `.exclude()`. The code then prints the status of each resulting consignment’s content object. It relies on Django’s ORM methods `filter`, `exclude`, and `Q`, with the data sourced from logistics and office booking models.

AI-generated description

Similar vizzes