Maxim Danilov
May 4, 2022

--

Really?

You have created a subquery in a query and you think you are avoiding duplicate queries?

Try to see the execution plan of your query in a Database. But I'm not sure you've heard about the execution plan.

Please, try to think before write some code, espesially in Django.

And believe me:

```

Post.objects.annotate(is_liked=Count('likes__user_id')).order_by('title')

```

is much better.

--

--

Maxim Danilov
Maxim Danilov

Written by Maxim Danilov

Python & Django Developer and speaker

No responses yet