I have a quick question about using a ForeignKey
in a model.
Lets say I have models Car
and EngineType
. I want a Car
to have EngineType
as a foreign key to populate the car's engine. That is easy enough.
My problem is this: Lets say that the EngineType
only should show active instances that are in production, so if they have stopped making the 3.5 liter 120 hp
engine from the 1970's I don't want it to appear on the selection of engine types when you are creating a new car. The other part of this is that I want all the records to stay in the car database for historical reporting. So what happens is I try and delete the engine mentioned above and if I have
on_delete=CASCADE
this doesn't do what I want because I lose the historical data. If I have
on_delete=PROTECT
I can't delete the unwanted engine model.
How do you handle this?