Deleting an model instance doesn't call the delete() method of related instances (even though they are removed).
|Reported by:||Ilya||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.1|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Do not calling delete method of models, when remove related objects.
from django.db import models class myModel1(models.Model): def delete(self): print "Delete myModel1 called" super(myModel1, self).delete() class myModel2(models.Model): m = models.ForeignKey(myModel1) def delete(self): print "Delete myModel2 called" super(myModel2, self).delete() >>> a = myModel1() >>> a.save() >>> b = myModel2(m = a) >>> b.save() ... >>> a.delete() Delete myModel1 called >>> myModel2.objects.all() 
Object of myModel2 class deleted, but method myModel2.delete not called.
Change History (4)
comment:1 Changed 7 years ago by
|Component:||Uncategorized → Database layer (models, ORM)|
|Patch needs improvement:||unset|
|Status:||new → closed|
|Summary:||Do not calling delete() method of models, when remove related objects → Deleting an model instance doesn't call the delete() method of related instances (even though they are removed).|