user7080065
user7080065

Reputation: 115

sort a list of django models by specific fields

I have a list of Django objects, all from the same class and those objects are not saved in the DB. I want to sort the list (again, a list of models) by a specific field in that class. How can I do that?

Thanks!

Upvotes: 1

Views: 2006

Answers (1)

user7080065
user7080065

Reputation: 115

so this is what I did and it worked for me:

list_of_models = sorted(list_of_models , key = lambda x: x.object.time)

Upvotes: 4

Related Questions