Commit 1b25ddd4 authored by Rurik Serzo's avatar Rurik Serzo

Merge branch 'serzo/forum'

parents ffaa1bd1 3ed9fd6f
......@@ -24,7 +24,7 @@ class Reply(models.Model):
reply_body = models.TextField()
pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE,null=True)
post = models.ForeignKey(Post,on_delete=models.CASCADE,null=True,related_name="posts")
post = models.ForeignKey(Post,on_delete=models.CASCADE,null=True,related_name="replies")
def getReply(self):
return "Reply by {} {} {}:<br>{}<br>".format(
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Forum{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'forum.css' %}">
{% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum</h1>
<h2>Forum posts:</h2>
<ul>
{% for post in posts %}
<li>
<a href="/forum/{{ post.id }}/details">
{{ post.post_title }} by {{ post.author.first_name }} {{ post.author.last_name }}
dated {{ post.pub_date|date:'d/m/Y' }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Forum{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'forum.css' %}">
{% endblock %}
{% block content %}
<h1 class="post-title">{{ post.post_title }}</h1>
<h2>by {{ post.author.first_name }} {{ post.author.last_name }} dated {{ post.pub_date|date:'d/m/Y' }}</h2>
<p>
{{ post.post_body }}
</p>
{% load static %}
{% if post.id == 1 %}
<img src="{% static 'post1.jpg' %}" alt="Leni Robredo">
{% elif post.id == 2 %}
<img src="{% static 'post2.jpg' %}" alt="Lady Gaga MET camp">
{% else %}
<img src="{% static 'post3.jpg' %}" alt="Bruno Mars Grammys 2022">
{% endif %}
<div>
{% for reply in post.replies.all %}
<p><span class="reply-author">{{ reply.author.first_name }} {{ reply.author.last_name }}, {{ reply.pub_date|date:'d/m/Y' }}</span>: {{ reply.reply_body }}</p>
{% endfor %}
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index, PostDetailView
urlpatterns = [
path("", index, name="index")
path("", index, name="index"),
path("<int:pk>/details", PostDetailView.as_view(), name="post-detail" )
]
app_name = "Forum"
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.views.generic.detail import DetailView
from .models import Post, Reply
def index(request):
posts = Post.objects.all()
formatted_posts = "FORUM POSTS:<br>"
for post in posts:
formatted_posts += post.getPost()
replies = Reply.objects.all().filter(post__post_title=post)
for reply in replies:
formatted_posts += reply.getReply()
formatted_posts += "<br>"
return HttpResponse(formatted_posts)
context = {
"posts": Post.objects.order_by("-pub_date"),
}
template = loader.get_template("forum/index.html")
return HttpResponse(template.render(context, request))
class PostDetailView(DetailView):
model = Post
\ No newline at end of file
@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@400;700&display=swap');
* {
font-family: 'Oswald', sans-serif;
background-color: #F4CCE1;
}
.reply-author {
font-weight:700;
}
.post-title {
text-align:center;
}
\ 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