Django delete user from userprofile
This is not how deleting objects work in Django.

The __del__ method is a Python mechanism and is called when an object is garbage collected. This would be a huge mess if database rows were dropped anytime an object goes out of scope. This is also why calling del object doesn't seem to have any side effect: Django still caches the value somewhere, you just got rid of your variable.

Instead, you should use the delete() method on a model instance or on a queryset. But in fact none of this code is required as the on_delete=models.CASCADE will take care of that for you: as soon as a User object is deleted, the other linked objects will be deleted as well.

The only thing missing is to automatically delete the User instance when a UserProfile instance is deleted. This is better implemented using signals as it will be called for both usages discussed earlier.

Alternatively, you can provide a method on your UserProfile model that will delete the underlying User and, thus, everything related to it:

def delete_user(self):
    self.User.delete()


But you won't be able to use it for bulk deletions.