0π
β
Yes, it is possible by using parent model form init method sample code:
class VForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(VForm, self).__init__(*args, **kwargs)
if self.instance.field == 'Y':
self.fields['field2'] = forms.ChoiceField(
choices=[(self.instance.field,
self.instance.field),], required=True)
This will filter the choice field restricted to only 1 choice, and a blank to select from .In above case βNβ as one of the choice fields is suppressed.
Same is the case for model fields also.
π€user956424
1π
You can do it using jquery. This is the way at clientside if suitable for you.
You can get value of form fields using id generated by form like(abc_1, abc_2 etc)
then you can compare it with some value and apply css (βdisableβ,true) to specific field using id.
π€jatinkumar patel
Source:stackexchange.com