3👍
✅
Your error does not lie in your posted code. You’ve followed the docs to the letter, so I would’ve been surprised if it did.
Instead, the error is found in your Alert class (models.py:55). for_user = models.ForeignKey()
has to be for_user = models.ForeignKey(User)
or for_user = models.ForeignKey(UserInfo)
, depending on which you prefer.
Your faulty code was trying to instantiate an instance of the class ForeignKey
, which calls it’s __init__()
method. That method will have a declaration of something like
def __init__(self, other_model):
and thus the error message saying that you’re missing one parameter. self
gets passed implicitly, read up on the Python classes docs if you’re interested.
-2👍
Try this
class UserInfo(models.Model):
user = models.OneToOneField(User)
pen_name = models.CharField(max_length=30)
activated = models.BooleanField()
def __unicode__(self):
return self.email + '-' + self.pen_name
def create_user_info(self, **kwargs):
u = kwargs["instance"]
created = kwargs["created"]
if not created:
UserInfo(user=u).save()
post_save.connect(UserInfo.create_user_info, sender=User)
Source:stackexchange.com