Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django override delete

I figured it out. I just put this on that Widget model:

def delete(self):
    files = WidgetFile.objects.filter(widget=self)
    if files:
        for file in files:
            file.delete()
    super(Widget, self).delete()
This 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.
Comment

PREVIOUS NEXT
Code Example
Python :: python datetime floor to hour 
Python :: how to show bar loading in python in cmd 
Python :: add a tuple to a dictionary python 
Python :: python linear regression 
Python :: download unsplash images python 
Python :: python remove by index 
Python :: python get input 
Python :: pandas df exact equals 
Python :: python anytree 
Python :: python index of lowest value in list 
Python :: run all python files in a directory in windows 
Python :: how to add reaction by message id in discord.py 
Python :: get index of all element in list python 
Python :: how to make a python program on odd and even 
Python :: python decorator 
Python :: channel hide command in discord.py 
Python :: python __lt__ 
Python :: numpy random 
Python :: how to check if string is in byte formate pythin 
Python :: python for enumerate 
Python :: cv2 frame size 
Python :: seaborn green color palette python 
Python :: read list stored as a string with pandas read csv 
Python :: #pip install commands 
Python :: traversing dictionary in python 
Python :: plt dashed line 
Python :: python check if key exist in json 
Python :: numpy get index of list of values 
Python :: list to dataframe pyspark 
Python :: how to append to a list in python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =