如果另一个表单的选择为“是”,我想将字段小部件更改为只读。此代码正常工作以启动窗口小部件状态readonly:
形式:
def __init__(self, *args, **kwargs):
super(AccountUpdate, self).__init__(*args, **kwargs)
self.fields['year'].widget.attrs['readonly'] = u'readonly'
但是如何根据GET请求中的选择字段进行操作?
型号:
class AccountUpdate(models.Model):
updateaddress = models.CharField(max_length=1, null=True, blank=True, choices=OPTION_CHOICES, default='N')
address = models.CharField('Your address?', max_length=50)
year = models.CharField(max_length=4)
选择
OPTION_CHOICES = (
('S', 'Yes'),
('N', 'No'),
)