So every model comes with some commonly used functions such as save and delete.
Delete is often overridden to set a boolean field such as is_active
to false, this way data is not lost. But sometimes a model exists that has information that, once created, should always exist and never even be "inactive". I was wondering what the best practice for handling this model's delete
method would be?
make it simply useless:
def delete(self):
return False
but that just seems odd. Is there maybe a Meta
option to disable deleting? is there any "nice" way to do this?
Well it depends, you cannot truly restrict deletion, because somebody can always call delete()
on queryset or just plain DELETE
sql command. If you want to disable delete button in django admin though, you should look here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With