Commit 8b7f321c authored by Trisha Angel Millena's avatar Trisha Angel Millena Committed by Ysabella Panghulan

Forum Page: Created forum.html, edited views.py, edited models.py

parent 01f330f3
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
# Create your models here.
......@@ -12,6 +13,9 @@ class ForumPost(models.Model):
def __str__(self):
return self.title
def get_absoluteurl(self):
return reverse('forum:forumpost-detail', kwargs={'pk': self.pk})
class Reply(models.Model):
body = models.CharField(max_length = 300)
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
......@@ -20,3 +24,6 @@ class Reply(models.Model):
def __str__(self):
return self.body
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum!</h1>
<h2>Forum posts:</h2>
<ul>
{% for forum in forums %}
<li>
<a href = "{{forum.get_absouluteurl}}">
{{ forum.title }} by {{ forum.author.first_name }} {{ forum.author.last_name }}
</a>
</li>
{% endfor %}
</ul>
<a href="/forum/forumposts/add/"> New Button </a>
<div>
<a href = "/dashboard/">Dashboard</a>
<a href = "/announcements/">Announcements</a>
<a href = "/assignments/">Assignments</a>
<a href = "/calendar/">Calendar</a>
</div>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
from django.views.generic.detail import DetailView
def index(request):
posts = ForumPost.objects.all()
forums = ForumPost.objects.all()
replies = Reply.objects.all()
welcomeMessage = 'Widget\'s Forum<br><br>Forum Posts:<br>'
context = {
'forums':forums,
'replies':replies
}
return render(request, 'forum/forum.html', context)
for post in posts:
for reply in replies:
if reply.forum_post.title == post.title:
welcomeMessage += post.title + ' by ' + post.author.first_name + ' ' + post.author.last_name
welcomeMessage += ' posted ' + post.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ':<br>' + post.body + '<br>'
welcomeMessage += 'Reply by ' + reply.author.first_name + ' ' + reply.author.last_name + ' posted '
welcomeMessage += reply.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ':<br>' + reply.body + '<br><br>'
return HttpResponse(welcomeMessage)
class ForumPostDetailView(DetailView):
model = ForumPost
template_name = 'widget_forum/forum.html'
\ No newline at end of file
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