我正在使用userena接收器,但出现以下错误...
/accounts/signup/ 处的 IntegrityError(1048,“列 'user_id' 不能为空”)
我假设我没有在我自己的 receivers.py 中正确访问用户。有人可以看看吗?
谢谢
接收器.py
from django.dispatch import receiver
from userena.signals import signup_complete
from accounts.models import Account
@receiver(signup_complete)
def handle_signup_complete(user, **kwargs):
try:
account = Account.objects.get(user=user)
except Account.DoesNotExist:
account = Account.objects.create()
account.credit_limit = 0
account.balance = 0
account.user = user
account.save()
模型.py
class Account(models.Model):
OPEN, FROZEN, CLOSED = 'Open', 'Frozen', 'Closed'
status = models.CharField(max_length=32, default=OPEN)
credit_limit = models.DecimalField(max_digits=10, decimal_places=1,
null=True, blank=True)
# For performance, we keep a cached balance
balance = models.DecimalField(max_digits=10, decimal_places=1,
null=True, blank=True)
#FK
user = models.OneToOneField(User)
用户信号.py
from django.dispatch import Signal
signup_complete = Signal(providing_args=["user",])
activation_complete = Signal(providing_args=["user",])
confirmation_complete = Signal(providing_args=["user","old_email"])
password_complete = Signal(providing_args=["user",])