Commit ae66f7b7 authored by Eury See's avatar Eury See

Created the Per Forum Post Details Page for the Forum application.

parent 3c88e239
# Generated by Django 4.1.7 on 2023-05-11 10:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Forum', '0003_alter_forumpost_author_alter_reply_author'),
]
operations = [
migrations.AddField(
model_name='forumpost',
name='replies',
field=models.ManyToManyField(blank=True, to='Forum.forumpost'),
),
]
from django.db import models
from Dashboard.models import WidgetUser
from django.urls import reverse
class ForumPost(models.Model):
title = models.CharField(max_length = 100)
......@@ -9,10 +10,12 @@ class ForumPost(models.Model):
def __str__(self):
return self.title
replies = models.ManyToManyField('self', blank=True)
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT)
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT, related_name='replies')
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
......
......@@ -20,7 +20,7 @@
<p1>Forum posts:</p1>
{% for post in posts %}
<li>{{post.title}} by {{post.author}}</a></li>
<li><a href="{% url 'Forum:forumpost-details' pk=post.pk %}">{{post.title}} by {{post.author}}</a></li>
{% endfor %}
<br>
......
<title>{% block title %} {{object.title}} {% endblock %}</title>
{% block styles %}
<style>
body {
background-color: rgb(202, 255, 206);
font-family: Georgia, serif;
font-size: 16px;
color: rgb(90, 154, 78);
}
</style>
{% endblock %}
{% block content %}
<div class="center">
<h1>{{ object.title }}</h1>
by {{ object.author }}
<br>
{{ object.pub_datetime }}
<br>
{{ object.body }}
<p>Post Replies:</p>
{% for reply in replies %}
by {{ reply.author }}
{{ reply.pub_datetime }}
{{ reply.body }}
{% empty %}
No replies yet.
{% endfor %}
<form method="post">
{% csrf_token %}
<br><button type="submit">
Edit Post
</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index, forum
from .views import (
index, forum, ForumDetailView)
from . import views
urlpatterns = [
path("", views.index, name="index"),
path('forum/', forum, name='forum'),
path('forum/forumposts/<int:pk>/details/', ForumDetailView.as_view(), name='forumpost-details'),
]
app_name = "Forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from .models import ForumPost, Reply
def forum(request):
# Query the database to get the forum posts
posts = ForumPost.objects.all()
# Pass the posts to the template
context = {'posts': posts}
# Render the template
return render(request, 'forum.html', context)
def index(request):
return_string = "<br>"
for reply in Reply.objects.all():
......@@ -24,4 +15,18 @@ def index(request):
return_string += "<br><br>"
html_string = "<html><head> Widget's Forum <br><br> Forum Posts: </head><body> {} </body><html>".format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
return HttpResponse(html_string)
def forum(request):
posts = ForumPost.objects.all()
context = {'posts': posts}
return render(request, 'forum.html', context)
class ForumDetailView(DetailView):
model = ForumPost
template_name = 'forumpost-details.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['replies'] = self.object.replies.all()
return context
No preview for this file type
# Generated by Django 4.1.7 on 2023-05-11 10:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widgetcalendar', '0005_alter_event_course_alter_event_location'),
]
operations = [
migrations.AlterField(
model_name='event',
name='activity',
field=models.TextField(default='', max_length=1000),
),
]
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