I am looking for a way to use Signals
to stop the User model
from deleting an entry, so I would not have to rewrite the User model. Instead, I'm looking to edit a model. A BooleanField is already set up. This way I can keep user in the database, and still have a way to eliminate the user from searches based on this field. Basically, I want to have something to do the following:
- Stop the deletion of the Instance
- Change
Instance.userprofile.deleted_user
toTrue
- Save
Instance.userprofile
I know how to get 2 & 3 done. But I just can't find a way to accomplish step 1, that does not involve editing the Default User model.
the code I do have for the issue, but as stated in the comment I do not have a way to stop the delete.
@receiver(pre_delete, sender=User)
def user_delete_handler(sender, instance, **kwargs):
# stop delete then do the following
instance.userprofile.deleted_user = True # edit linked model to mark user as deleted
instance.userprofile.save() # save linked model