0
我已經在this link中聲明瞭我的模型類....我現在想要定製如何爲我創建的Vehicle
對象添加/編輯ModelForm,因爲我希望年,製作,模型和製造商字段單獨提供,而不是參考Vehicle
類中的一個common_vehicle
字段。如何才能做到這一點?ModelForm問題
我已經在this link中聲明瞭我的模型類....我現在想要定製如何爲我創建的Vehicle
對象添加/編輯ModelForm,因爲我希望年,製作,模型和製造商字段單獨提供,而不是參考Vehicle
類中的一個common_vehicle
字段。如何才能做到這一點?ModelForm問題
你爲什麼不讓車輛繼承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