Форум сайта python.su
Имеются модели:
class Model1(models.Model):
pass
class Model2(models.Model):
model1 = models.ForeignKey(Model1)
class Model3(models.Model):
model2 = models.ForeignKey(Model2)
def model1_delete_handler(sender, instance, **kwargs):
if instance.model2_set.all().count() != 0:
...
def model2_delete_handler(sender, instance, **kwargs):
if instance.model3_set.all().count() != 0:
...
signals.pre_delete.connect(model1_delete_handler, sender=Model1, dispatch_uid = 'model1_delete')
signals.pre_delete.connect(model2_delete_handler, sender=Model2, dispatch_uid = 'model2_delete')
Офлайн