自上次见面以来的新通知(Django)



现在,我正在使用此视图,以告知用户他们的问题刚刚回答,

def notifications(request):
answers = Answer.objects.filter(question__user=request.user).order_by('-id')
....

,但这只是一个普通的HTML文本通知。我想通过将自上次出现的新通知的数量通知它们,使其更具动态性,就像我们在社交网络上看到的那样。

我该怎么做?

请帮助我使用此代码。预先感谢!

您需要在该人检查其通知的最后一次记录。您还需要保留创建答案的时间。一旦有了这两件事,您就可以进行类似的查询:

lastchecked = (query the last time the person checked their notifications.  This should be a datetime object.)
notification_count = Answer.objects.filter(question__user=request.user, created__gte=lastchecked).count()

最新更新