I implemented this thing using a remote flag for each model of my database, instead of moving things to a separate database as follows:
deleted = models.BooleanField(default=False)
And defined the soft_del function for each model as follows:
def soft_del(self):
self.deleted = True
self.save()
Thus, remote models will exist in the same database with the remote flag set to True.
Also, to create the effect of ON DELETE CASCADE, I added such soft_del functions for each model and gave the associated name to each foreign key in the model as follows:
class B(models.Model)
a = models.ForeignKey(A,related_name='related_Bs'))
and then call soft_del of the child when inside the soft_del of the parent:
def soft_del_A(self):
self.deleted = True
for b in A.related_Bs.all():
b.soft_del_B()
self.save()
source
share