Django display edited time only for edited comments

This is my model for Comment

class Comment(models.Model):
  content = models.TextField()
  dt_created = models.DateTimeField(auto_now_add=True)
  dt_updated = models.DateTimeField(auto_now=True)

  author = models.ForeignKey(User, on_delete=models.CASCADE)
  post = models.ForeignKey(Post, on_delete=models.CASCADE, related_name="comments")

  def __str__(self):
    return f"Comment by {self.author.username} on {self.post.title}"

and I am trying to display edited time if edited time != created time in the template

<div class="comment">
  <div class="comment-meta">
    {{comment.author.nickname}} | Date: {{comment.dt_created|date:"M, d Y H:i"}}
      {% if comment.dt_created != comment.dt_updated %} | Last edited: {{ comment.dt_updated|date:"M d, Y H:i" }}
      {% endif %}
  </div>
  <div class="comment-content">{{comment.content}}</div>
</div>
...

But somehow it is displaying dt_updated for all comments even the ones that are not edited.

I tried changing the code to check if it displays date when dt_created==dt_updated and it actually didn't display the edited time for all comments, including the comments that were edited. I also tried using comment.edited and it also didn't display edited time for all comments.

What is wrong with my code?

Вернуться на верх