我有一个名为Profile的模型,如下所示:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.TextField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.CharField(max_length=300)
country = models.CharField(max_length=30)
city = models.CharField(max_length=30)
organization = models.CharField(max_length=30)
编辑:
这是我处理用户更改的方式
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
我希望能够访问以下模型:
>>>> user = User.objects.get(pk=23)
>>>> user.profile
相反,我收到了此处描述的错误(粘贴时间有点长):https://pastebin.com/NRQVM0NK
你有什么暗示要解开我吗?
非常感谢