Commit fe45b7c1 authored by Tanya Yotoko's avatar Tanya Yotoko

modified forum templates and models.py

parent 7ee9735c
# Generated by Django 4.1.7 on 2023-05-10 11:51
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('forum', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='pub_datetime',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='reply',
name='forum_post',
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, related_name='forum_reply', to='forum.forumpost'),
),
]
......@@ -19,7 +19,7 @@ class Reply(models.Model):
body = models.TextField(default="")
author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost,on_delete=models.CASCADE,default="")
forum_post = models.ForeignKey(ForumPost,on_delete=models.CASCADE,default="",related_name='forum_reply')
def __str__(self):
return '{}'.format(self.body)
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h1>Welcome to Widget's Forum</h1>
<h2>Forum posts:</h2>
<h3>
{% for object in forum %}
<a href="{{ object.get_absolute_url }}">{{object.title}} by {{object.author.first_name}} {{object.author.last_name}}</a>
<br>
{% endfor %}
</h3>
<br>
<form action="forumposts/add">
<input type="submit" value="Add Post">
</form>
<h3>
<a href="../dashboard/">Dashboard</a> <br>
<a href="../announcements/">Announcements</a> <br>
<a href="../assignments/">Assignments</a> <br>
<a href="../calendar/">Calendar</a>
</h3>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Post{% endblock %}
{% block content %}
<h1>Add a New Post:</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Post">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
<h1>{{object.title}}</h1>
<h3>by {{object.author.first_name}} {{object.author.last_name}}</h3>
<h3>{{object.pub_datetime|date:'m/d/Y, h:i A'}}</h3>
<h3>{{object.body}}</h3>
<br>
<h2>POST REPLIES:</h2>
{% for reply in object.forum_reply.all %}
<h3>by {{reply.author.first_name}} {{reply.author.last_name}}</h3>
<h3>{{reply.pub_datetime|date:'m/d/Y, h:i A'}}</h3>
<h3>{{reply.body}}</h3>
<br>
{% endfor %}
<form action="../edit/">
<input type="submit" value="Edit Post">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Post{% endblock %}
{% block content %}
<h1>Edit Post</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Post">
</form>
{% endblock %}
\ No newline at end of file
......@@ -6,8 +6,6 @@ urlpatterns = [
path('forumposts/<int:pk>/details/',ForumPostDetailView.as_view(),name='forumpost-details'),
path('forumposts/add/',ForumPostCreateView.as_view(),name='forumpost-add'),
path('forumposts/<int:pk>/edit/',ForumPostUpdateView.as_view(),name='forumpost-edit'),
]
app_name = "forum"
app_name = "forum"
\ No newline at end of file
......@@ -20,6 +20,4 @@ class ForumPostCreateView(CreateView):
class ForumPostUpdateView(UpdateView):
model = ForumPost
fields = ['title','body','author']
template_name = 'forum/forumpost-edit.html'
template_name = 'forum/forumpost-edit.html'
\ 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