This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import forms | |
| from django.utils.safestring import mark_safe | |
| class CustomModelChoiceField(forms.ModelChoiceField): | |
| def label_from_instance(self, obj): | |
| return mark_safe("My Object custom label <strong>%i</strong>" % obj.id) | |
| class MyForm(forms.ModelForm): | |
| my_field = CustomModelChoiceField(label=_('The form label'), queryset=MyModel.objects.filter(), widget=forms.RadioSelect, empty_label=None) |