0
我有任务,但不知道如何实现它。任何帮助,将不胜感激!在模板中显示新对象的数量?
在我的django项目中,我有模态“任务”。任何任务都有很多评论。在下面你可以看到我的代码。当用户打开页面时,我需要显示一些新评论。例如,当用户出来页面时,它对该任务有4条评论,然后在一段时间进入页面后再次看到其他用户留下的新评论的数量。如何实现它?我有点舒服?
models.py:
class Task(models.Model):
comments = models.ManyToManyField("Comment")
class Comment(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.TextField()
created = models.DateTimeField(auto_now_add=True)
html.py:
(Number of new comments: ?)
List of comments:
{% for comment in task.comments.all %}
{{ comment.author }}
{{ comment.created }}
{{ comment.text }}
{% endfor %}
是的,我知道如何显示评论总数。那么,你能告诉我有关使用JavaScript的想法的更多细节吗?知道它不是很清楚。也许你有相同任务的例子或项目? –