Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django on delete set default

It depends on your business requirements. Should every Item always point to a valid Policy? And what's the requirement from business point-of-view when a Policy gets deleted? Should the Items pointing to it also be deleted? We don't know your requirements, so it's difficult to answer your question. These are your options from a technical perspective:

Set on_delete=CASCADE if you want the Item to be deleted when the Policy is deleted
Set on_delete=PROTECT if you don't want to allow any Policy to be deleted if there's still any Item pointing to it. In that case you'll have to try: policy.delete(); except ProtectedError: ... in your code to handle that situation.
Set on_delete=SET_DEFAULT if you know your default policy will not be deleted (you could override the delete method on Policy to avoid deleting the default policy).
Set on_delete=SET_NULL if an Item can have no Policy. That may be valid in certain business scenarios. But in this case you must also have null=True.
Comment

PREVIOUS NEXT
Code Example
Python :: Append a line to a text file using the write() function 
Python :: pandas compare two columns of different dataframe 
Python :: python check if string or list 
Python :: check if key exists in sesison python 
Python :: python get audio from video 
Python :: chatterbot python 
Python :: multiple channel deleteing command in discord.py 
Python :: try for loop python 
Python :: django generate openapi schema command line 
Python :: python regions 
Python :: download youtube video 
Python :: concatenate list in python 
Python :: Python get first element from list 
Python :: pandas list comprehension 
Python :: Insert list element at specific index 
Python :: Python Read the CSV file 
Python :: replace in lists py 
Python :: how many numbers greater than 100 using pytho 
Python :: values django 
Python :: django rest framework serializers 
Python :: python insert item into list 
Python :: python day of the year 
Python :: black python 
Python :: enum python string 
Python :: remove toggle/pandaslux 
Python :: re module documentation 
Python :: Reading Custom Delimited file in python 
Python :: full row visible in jupyter notebook 
Python :: how to append dict to dict in python 
Python :: pyqt button hover color 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =