【发布时间】:2011-05-12 20:35:32
【问题描述】:
我正在添加一个系统,为用户留下“通知”,以便他们下次登录时显示。我在 models.py 文件中创建了一个简单的 Notification 类。我有这个 UserInfo 类(在同一个 models.py 中)作为 socialauth 的一部分向 Django 的现有用户系统添加一些属性:
class UserInfo(models.Model):
user = models.OneToOneField(User, unique=True)
...
reputation = models.IntegerField(null=True, blank=True)
def add_notification(message):
notification = Notification(user=self.user, message=message)
notification.save
当我在控制台中尝试时,我得到了这样的结果:
>>> user = User.objects.get(id=14)
>>> user.userinfo.add_notification('you are an awesome intern!')
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: add_notification() takes exactly 1 argument (2 given)
>>>
我在这里缺少什么?我是一个 Django 菜鸟,所以也许这很容易。谢谢!
【问题讨论】:
标签: django-models django-authentication django-socialauth