Commit 86b4a25f authored by Chino Tesoro's avatar Chino Tesoro

updated forum app to add styling and posts with images

parent 5dbd99c4
# Generated by Django 4.0.3 on 2022-05-22 09:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_remove_reaction_announcement_reaction_announcement'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(verbose_name='Date Published'),
),
]
# Generated by Django 4.0.3 on 2022-05-22 09:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0004_post_author_reply'),
]
operations = [
migrations.AddField(
model_name='reply',
name='images',
field=models.ImageField(default='default.jpg', upload_to='forum'),
),
]
# Generated by Django 4.0.3 on 2022-05-22 10:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_reply_images'),
]
operations = [
migrations.RemoveField(
model_name='reply',
name='images',
),
migrations.AddField(
model_name='post',
name='images',
field=models.ImageField(default='default.jpg', upload_to='forum'),
),
]
......@@ -7,6 +7,7 @@ class Post (models.Model):
post_body = models.CharField(max_length=99999)
pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
images = models.ImageField (upload_to="forum", default = "default.jpg")
def __str__(self):
return f"{self.post_title} {self.post_body} {self.pub_date}"
......
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale-1.0">
<link rel="stylesheet" href="{% static 'forum/style.css' %}">
<title>{% block title %}Wahoo{% endblock %}</title>
</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 %}post details{% endblock %}
{%block content%}
<h1>{{ post.post_title }}</h1>
<h2>by {{ post.author }}, {{post.pub_date}}</h2>
<p>{{post.post_body}}</p>
{% if replies %}
<ul>
{% for reply in replies %}
<li>{{ reply.author }}, {{reply.pub_date}}: {{reply.reply_body}}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No replies are available.</p>
{% endif %}
<br /><br /><br /><img src="{{ post.images.url }}" alt="{{post.post_title}}" style="width:50%">
{% endblock %}
{%extends 'base.html'%}
{%load static%}
{%block title%}Forum{%endblock%}
{%block content%}
<h1>Welcome to Widget's Forum!</h1>
<p>Forum posts:</p>
{% if posts %}
<ul>
{% for post in posts %}
<li><a href = "posts/{{ post.id }}/details/">{{post.post_title}} by {{ post.author }} dated {{ post.pub_date }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No posts are available.</p>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -3,6 +3,7 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path("posts/<int:post_id>/details/", views.details, name = "details"),
]
app_name = "forum"
\ No newline at end of file
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from django.shortcuts import render
from .models import Post, Reply
posts = Post.objects.all()
replies = Reply.objects.all()
posts = Post.objects.order_by("pub_date")
replies = Reply.objects.order_by("pub_date")
finalstring = "FORUM POSTS:<br />"
for i in posts:
poststring = f"{i.post_title} by " + f"{i.author} dated " + f"{i.pub_date}:<br />" + f"{i.post_body}<br />"
finalstring += poststring
def index (request):
for i in replies:
context = {
"posts": posts
}
replystring = "Reply by " + f"{i.author} dated " + f"{i.pub_date}:<br \>" + f"{i.reply_body}<br />"
return render(request, "forum/index.html", context)
finalstring += replystring
def details (request, post_id):
def index (request):
try:
post = Post.objects.get (pk=post_id)
except Post.DoesNotExist:
raise Http404 ("Post does not exist!")
for reply in posts:
if reply.id == post_id:
post = reply
break
context = {
"post": post,
"replies": replies
}
return HttpResponse (finalstring)
return render(request, "forum/details.html", context)
......
# Generated by Django 4.0.3 on 2022-05-22 09:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_alter_widgetuser_profile'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile',
field=models.ImageField(default='default.jpg', upload_to='homepage'),
),
]
This diff is collapsed.
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