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.
The SortedSelectMultiple
class¶
- class parler.widgets.SortedSelectMultiple(attrs=None, choices=())¶
A multiple-select box which sorts it’s options.
The SortedCheckboxSelectMultiple
class¶
- class parler.widgets.SortedCheckboxSelectMultiple(attrs=None, choices=())¶
A checkbox group with sorted choices.