parler.widgets module¶
These widgets perform sorting on the choices within Python. This is useful when sorting is hard to due translated fields, for example:
- the ORM can’t sort it.
- the ordering depends on
gettext()
output. - the model
__unicode__()
value depends on translated fields.
Use them like any regular form widget:
from django import forms
from parler.widgets import SortedSelect
class MyModelForm(forms.ModelForm):
class Meta:
# Make sure translated choices are sorted.
model = MyModel
widgets = {
'preferred_language': SortedSelect,
'country': SortedSelect,
}
The SortedSelect
class¶
-
class
parler.widgets.
SortedSelect
(attrs=None, choices=())¶ A select box which sorts it’s options.