I am pretty new to django and have a question. I got a ModelForm using Widgets. Since I have a field called discount
which I only want to be editable if the displayed model fullfills some requirements, I make it read-only using a widget entry:
class Meta:
widgets = {'discount': forms.TextInput(attrs={'readonly': True})}
Now I want to make it possible to write to this field again, iff the Model (here called Order) has its field type set to integer value 0.
I tried to do so in the html template but failed. So my next idea is to make the widget somehow dependent to the model it displays, so in kinda pseudocode:
class Meta:
widgets = {'discount': forms.TextInput(attrs={'readonly': currentModel.type == 0})}
Is there a proper way to do something like this? Thanks in advance