Commit a93908a9 authored by Rac Gerard Elizaga's avatar Rac Gerard Elizaga

Updated forum app with templates

parent a418f376
......@@ -15,3 +15,5 @@ class Reply(models.Model):
reply_body = models.CharField(max_length=1000)
pub_date = models.DateTimeField('date published', auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null = True)
#ADD IMAGE TO POSTDETAILS PAGE
\ No newline at end of file
h3 {
color: orangered;
font-weight: bold;
}
h4 {
color: blue;
font-weight: lighter;
}
p {
color:green;
font-weight: bold;
}
body {
background-color: aquamarine;
}
a {
color:darkred
}
li {
color: brown;
}
img {
width: 200;
height: 200;
}
\ No newline at end of file
<html lang="en">
<head>
{% load static %}
<link rel="stylesheet" href="{% static "forum/style.css" %}">
<title>{% block title %}Title{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h3>Welcome to Widget's Forum!</h3>
<h4>Forum Posts:</h4>
{% if posts_list %}
<ul>
{% for i in posts_list %}
<li><a href="posts/{{ i.id }}/details/">{{ i.post_title}} by {{ i.author.first_name }} {{ i.author.last_name }} dated {{ i.pub_date|date:"SHORT_DATE_FORMAT" }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No posts are available.</p>
{% endif %}
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h3>{{ post.post_title }}</h3>
<h4>by {{ post.author.first_name }} {{ post.author.last_name }}, {{ post.pub_date|date:"SHORT_DATE_FORMAT" }}</h4>
<p>{{ post.post_body }}</p>
{% if replies_list %}
<ul>
{% for i in replies_list %}
<li>{{ i.author.first_name }} {{ i.author.last_name }}, {{ i.pub_date|date:"SHORT_DATE_FORMAT" }}: {{ i.reply_body }}</li>
{% endfor %}
</ul>
{% else %}
<p>No posts are available.</p>
{% endif %}
{% load static %}
<img src="{% static image_url %}" alt="Photo of Post"/>
{% endblock %}
......@@ -2,5 +2,10 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
#forum
path('', views.forumView, name='forum'),
#post/<post_id>/details/
path('posts/<int:post_id>/details/', views.postDetailsView, name='post details')
#note to self: id of posts are 3,4,5,6 according to shell query
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from .models import Post, Reply
def index(request):
message = 'FORUM POSTS:<br/>'
def forumView(request):
posts_list = Post.objects.order_by("pub_date")
context = {
"posts_list": posts_list
}
post = Post.objects.all()
reply = Reply.objects.all()
return render(request, "forum.html", context)
for i in post:
post_date = i.pub_date.date().strftime("%m/%d/%Y")
message += f'{i.post_title} by {i.author.first_name} {i.author.last_name} dated {post_date}:<br/>{i.post_body}<br/>'
for j in reply:
if j.post == i:
reply_date = j.pub_date.date().strftime("%m/%d/%Y")
message += f'Reply by {j.author.first_name} {j.author.last_name} dated {reply_date}:<br/>{j.reply_body}<br/>'
message += '<br/>'
def postDetailsView(request, post_id):
displayed_post = Post.objects.get(pk=post_id)
replies_list = Reply.objects.filter(post=displayed_post).order_by("pub_date")
image_url = f'forum/{displayed_post.id}.png'
context = {
"post": displayed_post,
"replies_list": replies_list,
"image_url": image_url
}
return HttpResponse(message)
\ No newline at end of file
return render(request, "post_details.html", context)
\ 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