【发布时间】:2020-06-04 12:54:24
【问题描述】:
我在医院管理系统上工作。在这个用户中,我首先注册为医生或患者,我有 userprofileinfo 模型。我也有用户注册的配置文件模型,这里出现问题我想要配置文件是仅在用户类型为 pateint 时创建,但我不知道如何在 django Signals 中检查条件。我尝试了一些方法,但它显示以下错误
type object 'UserProfileInfo' has no attribute 'instance'
文件:- userprofileinfo.py patientprofile.py
编辑:- 在一个很好的建议中,我做出了更改,例如当用户注册为 Doctor is_staff 时设置为 true,但当注册为患者时 is_staff 为 false,但当我在信号中使用它时,它总是返回 false。指向注意到在 django 管理站点中 is_staff 被勾选为医生和超级
@receiver(post_save, sender=User)
def update_profile_signal(sender, instance, created, **kwargs):
if created:
if instance.is_staff:
PateintProfile.objects.create(user=instance)
instance.pateintprofile.save()
【问题讨论】:
-
请上传您的代码。不是图!!!使用适当的缩进上传您的问题
标签: django django-models