【发布时间】:2020-11-29 12:15:56
【问题描述】:
尝试使用 post_save 扩展我的模型:
class Profile(models.Model):
account = models.OneToOneField(Account, on_delete=models.CASCADE)
def create_account_profile(sender, **kwargs):
if kwargs['created']:
account_profile = Account.objects.create(account=kwargs['instance'])
post_save.connect(create_account_profile, sender=Account)
得到以下错误:
Account() got an unexpected keyword argument 'account'
解决方案:
def create_account_profile(sender, instance, **kwargs):
if kwargs['created']:
account_profile = Profile.objects.create(account=instance)
post_save.connect(create_account_profile, sender=Account)
【问题讨论】:
标签: python-3.x django django-signals