N
N
nurzhannogerbek2017-04-16 07:19:06
Django
nurzhannogerbek, 2017-04-16 07:19:06

Display the number of new entries (comments)?

Hello! Need advice or examples on how to implement the following task.
There is a certain data model (in my case "Task") and each task has a lot of comments. When the page loads, it is necessary for the user to show some kind of notification that there is a new comment for this task. Display the number of new comments. For example, when leaving the page, there were 4 comments on the task, the user after some time went back to the page and must see the number of new comments left by other users (unread comments for these users). Do I need to make some kind of counter and compare it? How to bind it to a specific user and session. I will be glad to any idea.
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:
(Количество новых комментариев: ?)
Список комментариев:
{% for comment  in task.comments.all %}
     {{ comment.author }}
     {{ comment.created }}
     {{ comment.text }}
{% endfor %}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question