top | item 24049442

(no title)

stefano | 5 years ago

By default yes, but you can configure queries fetching behavior using select_related/prefetch_related to avoid the N+1 queries problem.

discuss

order

collyw|5 years ago

Sadly not so many people know how to use those. From the Django projects that I have inherited at least.

selectnull|5 years ago

Django ORM mainly hides the SQL from the developer (which is kind of the idea of any ORM). But if a developer does not understand the underlying SQL concepts, they will soon write performance wise horrific code. But, if you remove the ORM from that equation, I don't see how that same developer doesn't make the same mistakes. So in the end, I don't think that Django ORM (in its core) can help much in this area.

There are of course tools that can help with that (django-debugger and others).