Commit 5df3ae23 authored by Ron Rodillas's avatar Ron Rodillas

created the per post's details page

parent 3670b489
No preview for this file type
# Generated by Django 4.1.7 on 2023-05-13 15:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_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 django.urls import reverse
# Create your models here.
class ForumPost (models.Model):
......@@ -6,6 +7,7 @@ class ForumPost (models.Model):
body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
replies = models.ManyToManyField('self', blank=True)
def __str__(self):
return self.title
......@@ -13,20 +15,17 @@ class ForumPost (models.Model):
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
def get_name(self):
return self.title
def get_author_first_name(self):
return self.author.first_name
def get_absolute_url(self):
return reverse('forum:PostDetailView', kwargs={'pk': self.pk})
def get_author_last_name(self):
return self.author.last_name
class Reply (models.Model):
body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(auto_now_add=True)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE, related_name = 'post_replies')
def datetime_posted(self):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
\ No newline at end of file
......@@ -14,7 +14,8 @@ Widget's Forum
<div>
{% for post in posts %}
"{{post.get_name}}" by {{post.get_author_first_name}} {{post.get_author_last_name}}<br>
<a href = "{{post.get_absolute_url}}">"{{post.title}}" by {{post.author.first_name}} {{post.author.last_name}}</a>
<br>
{% endfor %}
<br><br><br>
<a href = "{% url 'forum:addPost' %}"><button>New Post</button></a>
......
{% extends 'base.html' %}
{% load static %}
{% block title %}
{{object.title}}
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<p1>
<h1>{{object.title}}</h1>
by {{object.author.first_name}}, {{object.author.last_name}}
<br>
{{object.datetime_posted}}
<br>
{{object.body}}
</p1>
<br><br>
<p2>
Post Replies: <br><br>
{% for reply in object.post_replies.all %}
by {{reply.author.first_name}} {{reply.author.last_name}} <br>
{{reply.datetime_posted}} <br>
{{reply.body}} <br>
<br>
{% endfor %}
</p2>
<br>
<button>Edit Post</button>
{% endblock %}
\ No newline at end of file
......@@ -4,6 +4,7 @@ from .views import *
urlpatterns = [
path('', index, name='index'),
path('forumposts/add/', PostCreateView.as_view(), name='addPost'),
path('forumposts/<int:pk>/details', PostDetailView.as_view(), name='PostDetailView'),
]
app_name="forum"
\ No newline at end of file
......@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.detail import DetailView
# Create your views here.
def index(request):
......@@ -13,4 +14,8 @@ class PostCreateView(CreateView):
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class PostDetailView(DetailView):
model = ForumPost
template_name = 'forum/forumpost-details.html'
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