update index page for Forum

parent 32d35732
body {
padding: 64px 160px;
}
#title {
margin: 0 0 64px;
}
#subtitle {
margin: 0 0 16px;
}
.posts {
padding: 0;
}
.posts > li {
margin: 0 0 16px;
width: 80%;
}
.posts > li a {
color: black;
text-decoration: none;
}
.posts > li a:hover {
text-decoration: underline;
}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'Forum/styles.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'Forum/index.css' %}">
{% endblock %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<article>
<h1 id="title">Welcome to Widget's Forum!</h1>
<h5 id="subtitle">Forum posts:</h5>
<ul class="posts">
{% for post in posts_sorted %}
<li><a href="/posts/{{ post.pk }}/details"><strong>{{ post.post_title }}</strong> by <strong>{{ post.author.first_name }} {{ post.author.last_name }}</strong> dated <strong>{{ post.pub_date|date:"d/m/Y" }}</strong></a></li>
{% endfor %}
</ul>
</article>
{% endblock %}
\ No newline at end of file
...@@ -6,23 +6,7 @@ def get_readable_time(timestamp): ...@@ -6,23 +6,7 @@ def get_readable_time(timestamp):
return timestamp.strftime("%m/%d/%Y") return timestamp.strftime("%m/%d/%Y")
def index(request): def index(request):
out = "FORUM POSTS: <br />" return render(request, 'Forum/index.html', {'posts_sorted': Post.objects.order_by('-pub_date')})
posts = Post.objects.all()
for post in posts:
out += f'{post.post_title} by {post.author.first_name} {post.author.last_name} dated {get_readable_time(post.pub_date)}: <br />'
out += f'{post.post_body} <br />'
post_replies = post.reply_set.all()
for reply in post_replies:
out += f'Reply by {reply.author.first_name} {reply.author.last_name} dated {get_readable_time(reply.pub_date)}: <br />'
out += f'{reply.reply_body} <br />'
out += '<br />'
return HttpResponse(out)
def details(request, post_id): def details(request, post_id):
try: try:
......
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