class DeviceForm(forms.ModelForm):
class Meta:
model = Device
fields = "__all__"
def __init__(self,*args,**kwargs):
super().__init__(*args, **kwargs)
if self.instance.pk:
if self.instance.device_type != "DC":
del self.fields["on_off_flag"]
del self.fields["speed_flag"]
del self.fields["direction_flag"]
我建议创建两个表单,一个只包含DC设备的字段,另一个包含所有字段的表单。然后在视图中,根据设备类型选择要使用的窗体。在
但我不推荐,因为你会发现这种方法是非常有限的
相关问题 更多 >
编程相关推荐