- class SelectWithNumberShortcuts(forms.widgets.Select):
- def __init__(self, attrs=None, choices=()):
- self.choices = [(iid,
- u"{shorcut} - {label}".format(**
- {'shorcut': i,
- 'label': label}))
- for i, (iid, label) in enumerate(choices)]
- super(SelectWithNumberShortcuts, self).__init__(attrs, choices)
Wanted to implement to have labels with numbers at the start instead of just text for quicker keyboard access.
So, instead of this:
<select name="name" id="id_document">
<option value="1">Label 1</option>
<option value="2">Label 2</option>
<option value="3">Label 3</option>
...
</select>
I would render this:
<select name="name" id="id_document">
<option value="1">1 - Label 1</option>
<option value="2">2- Label 2</option>
<option value="3">3 - Label 3</option>
...
</select>
Any ideas how this should be accomplished or why this doesn't work?