I have a model with an attribute which keeps track of the price. Right now, I have a list of that certain model. Is there anyway to rearrange the list to sort by that particular attribute? Is python smart enough to know that the attribute is a value which can be sorted? I am not keeping keeping track of the instances of a particular model using a database (it is not needed for what I am doing, so I cannot just retrieve the instances from the database in sorted order)
Thanks!
I have a model with an attribute which keeps track of the price. Right
Share
You can use the inbuilt
sortedfunction, together with a custom-made function that returns the price of an object:This would also work via any method of your class that returns the price, e.g.
See http://wiki.python.org/moin/HowTo/Sorting/ for more.