Commit 63a3069f authored by Trisha Angel Millena's avatar Trisha Angel Millena

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

parent fc0e6ade
from django.db import models from django.db import models
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
from django.urls import reverse
# Create your models here. # Create your models here.
...@@ -12,6 +13,9 @@ class ForumPost(models.Model): ...@@ -12,6 +13,9 @@ class ForumPost(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
def get_absoluteurl(self):
return reverse('forum:forumpost-detail', kwargs={'pk': self.pk})
class Reply(models.Model): class Reply(models.Model):
body = models.CharField(max_length = 300) body = models.CharField(max_length = 300)
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
...@@ -20,3 +24,6 @@ class Reply(models.Model): ...@@ -20,3 +24,6 @@ class Reply(models.Model):
def __str__(self): def __str__(self):
return self.body 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.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import ForumPost, Reply from .models import ForumPost, Reply
from django.views.generic.detail import DetailView
def index(request): def index(request):
posts = ForumPost.objects.all() forums = ForumPost.objects.all()
replies = Reply.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: class ForumPostDetailView(DetailView):
for reply in replies: model = ForumPost
if reply.forum_post.title == post.title: template_name = 'widget_forum/forum.html'
welcomeMessage += post.title + ' by ' + post.author.first_name + ' ' + post.author.last_name \ No newline at end of file
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)
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