我正在添加一個系統爲下次登錄時可以顯示的用戶留下「通知」。我在models.py文件中創建了一個簡單的Notification類。我有這樣的UserInfo類(在同一個models.py)對某些屬性Django的現有用戶系統添加爲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 noob,所以也許這很簡單。謝謝!
我期待有一個通知系統,通知會一直持續到用戶通過ajax調用關閉爲止,有點像Stack Overflow。你認爲消息可以做到這一點嗎? – gohnjanotis 2010-11-19 23:01:23
是的...我猜消息是一個非常不錯的功能...我也使用它...你應該考慮[這個答案](http://stackoverflow.com/questions/4229044/create-user-notification-system -in-django的/ 4229263#4229263)。 – crodjer 2010-11-20 04:47:53