0

I have task but dont know how to realise it. Any help would be appreciated!

In my django project I have modal "Task". Any task has a lot of comments. Here below you can see my code. I need to show number of new comments when user open the page. For example, when the user came out the page it was 4 comment to the task and then again after a certain time goes to a page and see the number of new comments left by other users. How to realise it? I am little bit comfused?

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 %}
Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193

1 Answers1

0

For the total number of comments I believe you can do this

(Number of new comments: {{task.comments.count}})

If you want to have the number of comments that arrived since you visited the page it sounds like you might need some javascript to hit some django url that will determine the difference based on the current state.

davidejones
  • 1,869
  • 1
  • 16
  • 18
  • Yes, I know how to show total number of comments. Well, could you tell me more details of your idea about using javascript? Right know it isn`t entirely clear. Maybe you have examples or projects with the same task? – Nurzhan Nogerbek Apr 16 '17 at 05:29