DEV Community

Discussion on: 666 Django projects checked for inefficient database queries. Over half had these 4 anti-patterns

Collapse
 
codereviewdoctor profile image
Code Review Doctor • Edited

The example code is imperfect, but the message I'm conveying is not "use my code". The message I'm trying to convey is "use foreign key values directly if you have to use foreign keys" - which is what Django docs themselves suggesting doing.

The advice of "use foreign keys directly" is fine, but yes I agree the way I illustrate the problem has other issues that are outside of scope of the purpose of the point I'm making

Using len(queryset) is not bad, if you work with objects from queryset after le

Agreed, I make that point in other words too: "Having said that though, if the records will need reading after the length is checked, then len(queryset) can be valid."