My Django app uses Django Suit as a tool for the Django admin app theme. One of the things that Suit can do is add and add widgets to create widgets, such as:
class PropertyForm(ModelForm): class Meta: model = Property widgets = { 'amount': EnclosedInput(prepend = "GBP"), }
Effect:

Although this is a nice feature, it would be more useful if I could add it dynamically, like (in pseudocode):
'amount': EnclosedInput(prepend = my_model_instance.currency)
I tried to override the init form as follows:
class PropertyForm(ModelForm): def __init__(self, *args, **kwargs): inst = kwargs["instance"] self._meta.widgets["amount"] = EnclosedInput(prepend = inst.currency) super(PropertyForm, self).__init__(*args, **kwargs)
It is strange that it only works when I set a breakpoint in the init method. There seem to be some time issues.
So my question is, what would be the best way (if at all possible) to implement this?
Roger source share