django override delete

Solutions on MaxInterview for django override delete by the best coders in the world

showing results for - "django override delete"
Colton
10 May 2016
1I figured it out. I just put this on that Widget model:
2
3def delete(self):
4    files = WidgetFile.objects.filter(widget=self)
5    if files:
6        for file in files:
7            file.delete()
8    super(Widget, self).delete()
9This triggered the necessary delete() method on each of the related objects, thus triggering my custom file deleting code. It's more database expensive yes, but when you're trying to delete files on a hard drive anyway, it's not such a big expense to hit the db a few extra times.