Commit a29cbfc6 authored by Christian Sarabia's avatar Christian Sarabia

Fix forum page and subpages

parent f0e3ec1f
......@@ -20,4 +20,4 @@
<p>There are no announcements.</p>
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
{% endblock %}
\ No newline at end of file
......@@ -5,7 +5,7 @@ from django.shortcuts import render
# Create your views here.
def index(request):
announcement_list = Announcement.objects.order_by("pub_date")
announcement_list = Announcement.objects.order_by("-pub_date")
context = {
"announcement_list": announcement_list,
}
......
# Generated by Django 3.2.12 on 2022-05-15 07:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0003_alter_reply_options'),
]
operations = [
migrations.AddField(
model_name='post',
name='post_image',
field=models.ImageField(blank=True, null=True, upload_to='forum/'),
),
]
......@@ -7,6 +7,7 @@ class Post(models.Model):
post_body = models.TextField(max_length=1500)
pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
post_image = models.ImageField(null = True, blank = True, upload_to = "forum/")
def __str__(self):
return self.post_title
......
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'forum/style.css' %}">
{% endblock %}
{% block title %}{{post.post_title}}{% endblock %}
{% block content %}
<h1>{{post.post_title}}</h1>
<h2>by {{post.author.first_name}} {{post.author.last_name}}, {{post.pub_date|date:"d/m/Y"}}</h2>
<div>
<p>
{{post.post_body}}<br><br>
{% if post.post_image %}
<p style="text-align:center"><img src = "{{ post.post_image.url }}"></p><br>
{% endif %}
{% if replies %}
Replies:<br>
<ul>
{% for reply in replies %}
<li>
<h4>by {{reply.author.first_name}} {{reply.author.last_name}}, {{reply.pub_date|date:"d/m/Y"}}:</h4>
<p> {{reply.reply_body}} </p>
</li>
{% endfor %}
</ul>
{% endif %}
</p>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'forum/style.css' %}">
{% endblock %}
{% block title %}Welcome to Widget's Forum{% endblock %}
{% block content %}
<h1>Forum</h1>
<div>
<h2>Forum posts:</h2>
{% if posts %}
<ul>
{% for post in posts %}
<li><a href="{% url 'forum:details' post.id%}">{{post.post_title}}</a> by {{post.author.first_name}} {{post.author.last_name}} dated {{post.pub_date|date:"d/m/Y"}}</li>
{% endfor %}
</ul>
{% else %}
<p>There is no post.</p>
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
app_name = "forum"
urlpatterns = [
path('', views.index, name="indexForum")
path('', views.index, name="indexForum"),
path('<int:post_id>/details', views.details, name="details")
]
from django.http import HttpResponse
from django.http import Http404
from .models import Post, Reply
from django.shortcuts import render
# Create your views here.
def index(request):
display_output = "<u><b>FORUM POSTS</u></b>:<br>"
posts = Post.objects.order_by("-pub_date")
context = {
"posts": posts
}
return render(request, "forum/index.html", context)
for post in Post.objects.all():
display_output += f"<b>{post.post_title} by {post.author.first_name} {post.author.last_name}</b> dated {str(post.pub_date)}:\
<br>{post.post_body}"
replies = Reply.objects.filter(post=post)
for reply in replies:
display_output += f"<br><b>Reply by {reply.author.first_name} {reply.author.last_name}</b> dated {reply.pub_date}:\
<br>{reply.reply_body}"
# display_output = "<u><b>FORUM POSTS</u></b>:<br>"
# for post in Post.objects.all():
# display_output += f"<b>{post.post_title} by {post.author.first_name} {post.author.last_name}</b> dated {str(post.pub_date)}:\
# <br>{post.post_body}"
# replies = Reply.objects.filter(post=post)
# for reply in replies:
# display_output += f"<br><b>Reply by {reply.author.first_name} {reply.author.last_name}</b> dated {reply.pub_date}:\
# <br>{reply.reply_body}"
display_output += "<br><br>"
# display_output += "<br><br>"
# return HttpResponse(display_output)
return HttpResponse(display_output)
\ No newline at end of file
def details(request, post_id):
try:
post = Post.objects.get(pk=post_id)
replies = Reply.objects.filter(post=post).order_by("-pub_date")
except Post.DoesNotExist:
raise Http404("Announcement does not exist!")
context = {
"post": post,
"replies": replies
}
return render(request, "forum/detail.html", context)
\ No newline at end of file
body {
font-family: sans-serif, Arial, Helvetica;
color:#035700;
line-height: 2;
}
div {
margin: auto;
width: 50%;
border: 3px solid rgb(194, 7, 169);
padding: 30px 40px 40px 40px;
}
h1 {
font-size: 40px;
text-align: center;
text-decoration: underline;
}
h2 {
font-size: 28px;
margin: 0px 0px 10px 0px;
text-align: center;
}
li {
font-size: 20px;
}
p {
font-size: 20px;
}
span {
font-weight: bold;
}
span.perfect {
color: rgb(96, 189, 96);
}
span.passing {
color:#bb5959
}
img {
max-width: 100%;
height: auto;
}
a {
color:#891fa3;
}
\ 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