【发布时间】:2011-02-19 10:50:36
【问题描述】:
我已经声明了我的模型类,如 this link....我现在想自定义我为 Vehicle 对象添加/编辑 ModelForm 的渲染方式,我想要年份、品牌、型号和制造商字段将单独呈现,而不是引用 Vehicle 类中的一个 common_vehicle 字段。如何做到这一点?
【问题讨论】:
标签: django django-forms
我已经声明了我的模型类,如 this link....我现在想自定义我为 Vehicle 对象添加/编辑 ModelForm 的渲染方式,我想要年份、品牌、型号和制造商字段将单独呈现,而不是引用 Vehicle 类中的一个 common_vehicle 字段。如何做到这一点?
【问题讨论】:
标签: django django-forms
为什么不让 Vehicle 继承 CommonVehicle? (当然,这取决于你为什么在那里有那个 FK——你可能真的需要它,但我猜不是)
代替:
class Vehicle(models.Model):
...
common_vehicle = models.ForeignKey(CommonVehicle)
用途:
class Vehicle(CommonVehicle):
...all your other Vehicle fields here, but not the FK to CommonVehicle
【讨论】: