简体   繁体   中英

Django: Deleting a User Profile

If I have the following code to create a user profile, do I have to delete it when I delete the user from the db. If so, how?

def create_user_info(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

Assuming that you have a OneToOneField on your UserProfile model which points to User, then you do not have to delete the profile explicitely.

In that case, Django's delete cascade will automatically follow the relationship backwards from the User to the Profile and delete the profile object for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM