About Sorting a List of Model Instances with Lambda
Use lambda
returning a tuple to sort a list of model instances by two or more fields, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Note that whenever possible, you should instead do the sorting at the database level, that is, QuerySets.
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 Python 3
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.