Commit a21d3721 authored by Eury See's avatar Eury See

Fixed Post Replies in the Forum Post Details page.

parent d73659ee
# Generated by Django 4.1.7 on 2023-05-12 18:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_alter_widgetuser_department'),
('Forum', '0005_alter_forumpost_pub_datetime_alter_reply_author'),
]
operations = [
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='Dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='forum_post',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='post_replies', to='Forum.forumpost'),
),
]
......@@ -18,10 +18,9 @@ class ForumPost(models.Model):
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT, related_name='replies')
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT)
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE, related_name='post_replies')
def __str__(self):
return self.body
return self.body
\ No newline at end of file
......@@ -21,9 +21,11 @@
{{ object.body }}
<h2>Post Replies:</h2>
{% for reply in replies %}
{% for reply in object.post_replies.all %}
by {{ reply.author }}
<br>
{{ reply.pub_datetime }}
<br>
{{ reply.body }}
{% empty %}
No replies yet.
......@@ -32,10 +34,8 @@
<br>
<br>
<button type="submit">
<a href="{% url 'Forum:forumpost-edit' pk=forumpost.pk %}">Edit Post</a>
<a href="{% url 'Forum:forumpost-edit' pk=object.pk %}">Edit Post</a>
</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
......@@ -34,7 +34,8 @@ class ForumListView(ListView):
class ForumDetailView(DetailView):
model = ForumPost
template_name = 'forumpost-details.html'
context_object_name = 'post'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['replies'] = self.object.replies.all()
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment