Tom, You could try doing this clear logic in a pre_delete signal. You might have to test out the timing of when the signals get called but it should call pre_delete for all deleted models. In this case it would call pre_delete on model2 before model1 but you should be able to get what you are looking for.
http://docs.djangoproject.com/en/dev/ref/signals/#pre-delete On Tue, Apr 13, 2010 at 8:21 AM, cootetom <coote...@gmail.com> wrote: > Hi, I'm trying to figure out the way django deletes models so that I > can clear the correct references that I need to prior to deleting. So > I have models set up with overrided delete functions so that I can do > clears before the actual delete. However, it appears the delete > functions in a model don't get called in the cascade of deletes so not > each child model gets to do it's clear of linked data before > deleting. > > def model1(models.Model): > def delete(self): > self.related_model.clear() > super(model1, self).delete() > > def model2(models.Model): > model2 = models.ForeignKey(model2) > > def delete(self): > self.another_related_model.clear() > super(model2, self).delete() > > > So if I do model1.delete() then it will do it's clear but it appears > it won't do the clear from model2? Am I getting this behaviour right > or am I doing something wrong here? > > The model class seems like the best place to put delete logic in so > that when it's deleted it clears any data it needs to first. > > - Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- ======================================= 株式会社ビープラウド イアン・ルイス 〒150-0021 東京都渋谷区恵比寿西2-3-2 NSビル6階 email: ianmle...@beproud.jp TEL:03-6416-9836 FAX:03-6416-9837 http://www.beproud.jp/ ======================================= -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.