Commit cfffc4c0 authored by Ron Rodillas's avatar Ron Rodillas

modified the home page for the forum app

parent a6960e20
......@@ -13,6 +13,12 @@ class ForumPost (models.Model):
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
def get_name(self):
return self.title
def get_author(self):
return self.author
class Reply (models.Model):
body = models.TextField()
author = models.CharField(max_length=100)
......
{% extends 'base.html' %}
{% load static %}
{% block title %}
Widget's Forum
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum</h1>
<h2>Forum posts:</h2>
<div>
{% for post in posts %}
"{{post.get_name}}" by {{post.get_author}}<br>
{% endfor %}
<br><br><br>
<button>New Post</button>
<br><br>
<a href="{% url 'dashboard:index' %}"> Dashboard</a>
<br>
<a href="{% url 'announcements:index' %}"> Announcements</a>
<br>
<a href="{% url 'Assignments:index' %}"> Assignments</a>
<br>
<a href="{% url 'calendar_app:index' %}"> Calendar</a>
<br>
</div>
{% endblock %}
\ No newline at end of file
......@@ -4,17 +4,7 @@ from .models import ForumPost, Reply
# Create your views here.
def index(request):
return_string = "Widget's Forums <br> <br> Forum Posts:<br>"
for i in ForumPost.objects.all():
return_string+=(
i.title + " by " + i.author + " posted " + i.datetime_posted() + ":<br>"
+ i.body + "<br>"
)
for n in Reply.objects.all():
if n.forum_post == i:
return_string+=(
"Reply by " + n.author + " posted " + n.datetime_posted() + ":<br>"
+ n.body + "<br>"
)
return_string+="<br>"
return HttpResponse(return_string)
\ No newline at end of file
post_list = reversed(ForumPost.objects.all())
return render(request,"widget_group3/forum.html",{"posts":post_list})
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_group3.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
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