[Answer]-Ordering by model method

1👍

order_by is applied at the database level (ie in the raw SQL) so you can’t call a function with it. You can get all your food_companies and sort them using isopen as a key, though. Something like:

sorted_companies = sorted(food_companies.objects.all(),
                          key=lambda food_company: food_company.isopen())
👤xnx

Leave a comment