Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created March 4, 2017 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/00801ab59bd09325e5d92c32a99f89d8 to your computer and use it in GitHub Desktop.
Save sivabudh/00801ab59bd09325e5d92c32a99f89d8 to your computer and use it in GitHub Desktop.
How to query for Min and Max at the same time
>>> from django.db.models import Max, Min
>>> Store.objects.annotate(min_price=Min('books__price'), max_price=Max('books__price'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment