Commit 89800a4e authored by Andre Dalwin C. Tan's avatar Andre Dalwin C. Tan

Added forumpost-details.html

parent eb52c5d5
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
class ForumPost(models.Model):
......@@ -10,10 +11,14 @@ class ForumPost(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('forum:forumpostdetails', kwargs={'pk': self.pk})
class Reply(models.Model):
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE, related_name="replies")
body = models.CharField(max_length=1000)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField("Published Date and Time", auto_now_add=True)
......
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1> {{ object.title }} </h1>
<h2> {{ object.author.first_name }} {{ object.author.last_name }}</h2>
<h3> {{ object.pub_datetime|date:"m/d/Y, h:i A" }} </h3>
<p> {{ object.body }} </p> <br>
Post Replies:
<ul>
{% for reply in object.replies.all %}
<li>
<p>by {{ reply.author.first_name }} {{ reply.author.last_name }}</p>
<p>{{ reply.pub_datetime|date:"m/d/Y, h:i A" }}</p>
<p>{{ reply.body }}</p>
</li>
{% endfor %}
</ul>
<form action="../edit">
<button type="Submit">Edit Post</button>
</form>
{% endblock %}
......@@ -4,6 +4,10 @@ from . import views
urlpatterns = [
path("", views.forum, name="index"),
path("forumpost/<int:pk>/details/", views.ForumDetailView.as_view(), name="forumpostdetails"),
path("forumpost/add/", views.ForumCreateView.as_view(), name="forumpostadd"),
path("forumpost/<int:pk>/edit/", views.ForumUpdateView.as_view(), name="forumpostedit"),
]
......
......@@ -9,6 +9,20 @@ from django.shortcuts import render
def forum(request):
context = {
"forumpost" : ForumPost.objects.all(), #.order_by('pub_datetime')
"forumpost" : ForumPost.objects.all().order_by('pub_datetime'),
}
return render(request, 'forum/forum.html', context)
class ForumDetailView(DetailView):
model = ForumPost
template_name = 'forum/forumpost-details.html'
class ForumCreateView(CreateView):
model = ForumPost
template_name = 'forum/forumpost-add.html'
fields = ['title', 'body', 'author']
class ForumUpdateView(UpdateView):
model = ForumPost
template_name = 'forum/forumpost-edit.html'
fields = ['title', 'body', 'author']
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