python - Django:删除用户配置文件

标签 python django django-users

如果我有以下代码来创建用户配置文件,当我从数据库中删除用户时是否必须删除它?如果是,怎么办?

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

post_save.connect(create_user_profile, sender=User)

最佳答案

假设您的 UserProfile 模型上有一个指向 User 的 OneToOneField,那么您不必明确删除配置文件。

在这种情况下,Django 的删除级联会自动按照从用户到配置文件的关系向后删除,并为您删除配置文件对象。

关于python - Django:删除用户配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11800913/

相关文章:

python - 交叉编译 Python 2.7.4+

javascript - `$getjson` 从 Django 到 javascript 不起作用

django - 错误 : "relation "django_comments"does not exist"

Django - 获取用户的名字和姓氏

python - Django 管理器不可用; 'auth.User' 已被交换为 'users.MyUser'

Python - BeautifulSoup 抓取非标准网络表

python - 如何从一列中对 Pandas 数据框进行排序

python - Google App Engine - NeedIndexError : no matching index found

python - 将图像上传到 s3 后,上传随附的缩略图

python - 如何匹配这个正则表达式?