Commit cfffc4c0 authored by Ron Rodillas's avatar Ron Rodillas

modified the home page for the forum app

parent a6960e20
...@@ -12,6 +12,12 @@ class ForumPost (models.Model): ...@@ -12,6 +12,12 @@ class ForumPost (models.Model):
def datetime_posted(self): def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') 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): class Reply (models.Model):
body = models.TextField() body = models.TextField()
......
{% 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 ...@@ -4,17 +4,7 @@ from .models import ForumPost, Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
return_string = "Widget's Forums <br> <br> Forum Posts:<br>" post_list = reversed(ForumPost.objects.all())
for i in ForumPost.objects.all(): return render(request,"widget_group3/forum.html",{"posts":post_list})
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
<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/ ...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
""" """
from pathlib import Path from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
...@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_group3.urls' ...@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_group3.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ '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