我正在尝试为创建的每个用户帐户创建一个配置文件。我正在使用 Django 1.4 和 python 2.7。
我有我的Profile
模型课:
class Profile(models.Model):
... profile fields ...
user = models.OneToOneField(User)
然后我使用 post save 信号来创建Profile
:
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
#Profile(user=instance).save()
post_save.connect(create_user_profile, sender=User, dispatch_uid="accounts.models")
如果我使用Profile.objects.create(user=instance)
我得到错误:
save() takes no arguments (3 given)
但如果我使用Profile(user=instance).save()
我会得到错误:
save() takes no arguments (1 given)
我基本上直接从 django 文档中复制了这个。
我真的不确定这里出了什么问题,所以任何帮助都将不胜感激。
编辑
问题已在评论中解决:
我有 def
save():
而不是def save(self, *args, **kwargs):