2👍
✅
Change
items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))
to
items.sort(lambda x, y: cmp(x['transper'], y['transper']))
(This works well with the builtin cmp
function because the transper
fields are converted to int
s by the nice_percentage
function, which is called as part of add_percentages
)
If that doesn’t produce the order you wanted, simply switch objects x
and y
.
If instead you need to sort it in the template (it’s typically a bad idea to mess with third-party apps’ source code), you can use the dictsort
filter:
{% for item in languages|dictsort:"transper" %}
Again, if that’s not the order you wanted, use dictsortreversed
.
0👍
The latest development version of Pootle, to become Pootle 2.2, now remembers which column you have selected to sort on. So a page reload will now remember the order you last used.
- [Answered ]-Confusion between celery and celeryd
- [Answered ]-Python sharing data across all modules in django app
- [Answered ]-Django registering site with admin?
- [Answered ]-Django method call from template sets named variable. How is this even possible?
- [Answered ]-Django templatetag
Source:stackexchange.com