I've tried to implement the comments within the html page after creating them in my models and I have migrated them but they still wont appear within the page although when I add a comment from the admin side of the website the add comment button I added in before the else statement in the html disappears, which means that it isn't empty but the comments still wont show?
Models.py
class Photo(models.Model):
category=models.ForeignKey(Category,on_delete=models.SET_NULL,null=TRUE,blank=TRUE)
image=models.ImageField(null=False,blank=False)
description= models.TextField()
def __str__(self):
return self.description
class Comment(models.Model):
user = models.ForeignKey(UserProfile, related_name="profile", on_delete=models.CASCADE)
photo = models.ForeignKey(Photo, related_name="comments", on_delete=models.CASCADE)
text = models.TextField()
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.user.user.username + ': ' + self.text
and then here is the Html portion
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible" content="IE-edge'>
<title>Photo</title>
<meta name='viewport' content='width-device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body class="m-5">
<div class="container">
<div class="row justify-content-center">
<div class="col">
<a href="{% url 'Clinician' %}" class="btn btn-dark my-3">Go Back</a>
<div style="height: 90vh;">
<img style="max-width: 100%; max-height: 100%;"
src="{{photo.image.url}}">
<p>
{{photo.description}}
</p>
<h4>Comments...</h4>
{% if not photo.comments.all %}
No Comments Yet...<a href="#">
add one
</a>
{% else %}
{% for comment in photo.comment.all %}
<strong>
{{ comment.date }}
</strong>
<br/>
{{ comment.text }}
{% endfor %}
{% endif %}
</div>
</div>
</div>
</div>
</body>