在这种情况下是否有一些巧妙的方法可以执行删除?
class Bus(models.Model):
wheel = OneToOneField(Wheel)
class Bike(models.Model):
wheel = OneToOneField(Wheel)
pedal = OneToOneField(Pedal)
class Car(models.Model):
wheel = OneToOneField(Wheel)
class Wheel(models.Model):
somfields
car = Car()
wheel = Wheel()
wheel.save()
car.wheel = wheel
car.save()
car.delete() # I want to delete also wheel (and also all stuff pointing via OneToOneField eg pedal)
我需要覆盖 Car、Bike、Bus 模型的删除方法还是有更好的方法?其他选项是在 Wheel 模型上创建字段 car、bike、bus,但这没有多大意义。