使用Django SutModelForm自动创建form实例化对象后,只关联了设置外键的另一个模型ProductModelForm中的字段(product_model),SutModelForm怎么添加另一个模型ProductModelForm中的多个字段(product_type和product_factory)到 form = SutModelForm()中
class ProductInfo(models.Model):
product_model = models.CharField(verbose_name="产品型号", max_length=32)
product_name = models.CharField(verbose_name="产品名称", max_length=32)
product_factory = models.CharField(verbose_name="生产厂家", max_length=32)
# 产品类型
type_choice = {
(1, '动态仪器'),
(2, '振动传感器'),
(3, '位移传感器'),
(4, '压力传感器'),
}
type = models.SmallIntegerField(verbose_name="产品类型", choices=type_choice, default=1)
def __str__(self):
return self.product_model
class SutInfo(models.Model):
"""样品信息"""
entrust_num = models.ForeignKey(verbose_name="合同编号", to="EntrustInfo", to_field="entrust_id",
on_delete=models.CASCADE)
deliver_choice = {
(1, "送样上门"),
(2, "快递"),
}
deliver = models.SmallIntegerField(verbose_name="收样方式", choices=deliver_choice, default=1)
type = models.ForeignKey(verbose_name="样品型号", to="ProductInfo", to_field="id",
on_delete=models.CASCADE)
sn = models.CharField(verbose_name="出厂编号", max_length=32)
manage_sn = models.CharField(verbose_name="管理编号", max_length=32)
sample_sn = models.CharField(verbose_name="样品编号", max_length=14)
receive_date = models.DateTimeField(verbose_name="收样日期")
apparent_choice = {
(1, '完好'),
(2, '锈蚀严重'),
(3, '破损'),
}
apparent = models.SmallIntegerField(verbose_name="外观状态", choices=apparent_choice, default=1)
比如在这个对话框里不止显示ProductInfo中的product_model产品型号,增加显示ProductInfo中的product_factory 。