M
M
maxclax2015-03-22 22:32:16
Django
maxclax, 2015-03-22 22:32:16

How to safely delete in Django?

Please tell me how to implement safe deletion in Django. It is necessary for me that it would not be possible to delete the object if there is at least one connection with another object. For example


Remove user.model.verbose_name?
Are you sure you want to delete user.model.verbose_name "[email protected]"? All of the following related objects will also be removed:
User.model.verbose_name: [email protected] Log
entry: Changed "[email protected]" - Changed password.
Log Entry: Changed "[email protected]" - Changed password.
Log Entry: Removed "[email protected]"
Log Entry: Removed "[email protected]"
Log Entry: Removed "[email protected]"
Log Entry: Removed "[email protected]"

now this should not be deleted due to the fact that there is some kind of connection.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-03-22
@maxclax

See ForeignKey.on_delete , you need to put on_delete=models.PROTECT in the foreign key field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question