在Django中,如何继承字段以填充d

2024-09-27 09:28:29 发布

您现在位置:Python中文网/ 问答频道 /正文

在Django中,如何基于从下拉列表中选择的值填充数据。 这些字段也是从另一个模型继承的。 例如: 类DeviceInfo有4个字段,类似于继承到类链接

如何设置视图,以便通过下拉选择name它将预填充位置、类型,然后用户可以填写rest字段

型号:

class DeviceInfo(models.Model):
    name = models.CharField(max_length=20, default='')
    location = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0')
    type = models.ForeignKey(Types, on_delete=models.SET_NULL, null=True)

class Links(DeviceInfo, models.Model):
    {other fields}

形式

class DeviceInfo_form(forms.ModelForm):

    class Meta:
        model = DeviceInfo
        fields = '__all__'
        field_classes = {
            'json_field': JSONFormField,
        }

感谢您抽出时间回答


Tags: 数据djangoname模型视图default类型field

热门问题