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...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
I'll give that a go later. I don't suppose it matters what order they
are called in because it's only clearing references to do with the
model instance it's calling from.
> > django-users...@googlegroups.com<django-users%2Bunsubscribe@google groups.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-9837http://www.beproud.jp/
> =======================================
At the moment the only approach I can think of is to define functions
for deleting models and do the clear logic before calling delete. This
seems really ugly to me but I can't see any other way.
def deleteModal2(obj):
obj.related_model.clear()
obj.delete()
def deleteModal1(obj):
for childObj in obj.related_model.all():
deleteModal2(childObj)
obj.related_model.clear()
obj.delete()
Any more ideas?
Also found this article on the net which details the options for this
problem nicely
http://stackoverflow.com/questions/2475249/what-are-the-options-for-overriding-djangos-cascading-delete-behaviour