Deleting an model instance doesn't call the delete() method of related instances (even though they are removed).
|Reported by:||ilblackdragon||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 6 years ago by SmileyChris
- Component changed from Uncategorized to Database layer (models, ORM)
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed
- Summary changed from Do not calling delete() method of models, when remove related objects to Deleting an model instance doesn't call the delete() method of related instances (even though they are removed).