Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goutomroy/14bedd9d259b70de8c3526a64f74cfad to your computer and use it in GitHub Desktop.
Save goutomroy/14bedd9d259b70de8c3526a64f74cfad to your computer and use it in GitHub Desktop.
# Don't
most_liked = 0
for entry in Entry.objects.all():
if entry.likes > most_liked:
most_liked = entry.likes
# Do
most_liked = Entry.objects.all().aggregate(Max('likes'))['likes__max']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment