From 0b608cc67e51eecfe043524d08acacf2e857dd0a Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Wed, 18 Jul 2012 00:50:43 +0200 Subject: [PATCH] Minor extension: allow apps to override the type label in the add form easily When overriding apps, this turns out to be a very useful feature to have. --- polymorphic/admin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/polymorphic/admin.py b/polymorphic/admin.py index 3035fcd..c03980f 100644 --- a/polymorphic/admin.py +++ b/polymorphic/admin.py @@ -25,7 +25,15 @@ class PolymorphicModelChoiceForm(forms.Form): """ The default form for the ``add_type_form``. Can be overwritten and replaced. """ - ct_id = forms.ChoiceField(label=_("Type"), widget=AdminRadioSelect(attrs={'class': 'radiolist'})) + #: Define the label for the radiofield + type_label = _("Type") + + ct_id = forms.ChoiceField(label=type_label, widget=AdminRadioSelect(attrs={'class': 'radiolist'})) + + def __init__(self, *args, **kwargs): + # Allow to easily redefine the label (a commonly expected usecase) + super(PolymorphicModelChoiceForm, self).__init__(*args, **kwargs) + self.fields['ct_id'].label = self.type_label