ModelForm问题

时间:2010-05-14 09:15:30

标签: django django-forms

我已经在this link中声明了我的模型类....我现在想要自定义我对Vehicle对象的添加/编辑ModelForm的呈现方式,我想要年份,make单独呈现的模型和制造商字段,而不是引用common_vehicle类中的一个Vehicle字段。怎么办呢?

1 个答案:

答案 0 :(得分:2)

为什么不让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
相关问题