I am developing an app where I need some of the data to be protected even when some models are deleted. I've been reading on the on_delete options, and seems to be a lot of warnings against using on_delete=DO_NOTHING. In my case, I need the results to be maintained even when a yacht or event gets deleted. The basic structure is this;
# models.py
class Yacht(models.Model):
yacht_name=models.CharField(max_length=100)
class Event(models.Model):
event_name=models.CharField(max_length=100)
yachts = models.ManyToManyField(Yacht, through="Result")
class Result(models.Model):
yacht = models.ForeignKey(Yacht, on_delete=DO_NOTHING)
event = models.ForeignKey(Event, on_delete=DO_NOTHING)
ranking = models.IntegerField(max_lenght=4)
For record keeping, I need the results to remain even if a yacht or event is deleted. What is the best approach here? Some thoughts;
- Create additional Result field (_yacht = models.CharField()) and use a post_save signal to provide a string.
- Create a separate table to keep records of the events. Table gets created/updated at post_save
Thanks in advance,
J