Commit ec031afe authored by Eury See's avatar Eury See

Created Add New Forum Post Page for the Forum application.

parent ae66f7b7
# Generated by Django 4.1.7 on 2023-05-12 17:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0002_alter_widgetuser_department'),
('Forum', '0004_forumpost_replies'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='pub_datetime',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='replies', to='Dashboard.widgetuser'),
),
]
......@@ -6,11 +6,14 @@ class ForumPost(models.Model):
title = models.CharField(max_length = 100)
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.PROTECT)
pub_datetime = models.DateTimeField()
pub_datetime = models.DateTimeField(auto_now_add=True, null=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('Forum:forumpost-details', kwargs={'pk':self.pk})
replies = models.ManyToManyField('self', blank=True)
class Reply(models.Model):
......
<title>{% block title %} Add Post {% endblock %}</title>
{% block styles %}
<style>
body {
background-color: #FEA8A5;
font-family: Georgia, serif;
font-size: 16px;
font-weight: bold;
color:#c35c5a;
}
</style>
{% endblock %}
{% block content %}
<div style="text-align: left;">
<h1>Add a new post:</h1>
</div>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Post</button>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import (
index, forum, ForumDetailView)
index, forum, ForumDetailView, AddForumPostView)
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'),
path('forum/forumposts/add/', AddForumPostView.as_view(), name='forumpost-add'),
]
app_name = "Forum"
\ No newline at end of file
......@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import ForumPost, Reply
......@@ -30,3 +31,14 @@ class ForumDetailView(DetailView):
context = super().get_context_data(**kwargs)
context['replies'] = self.object.replies.all()
return context
class AddForumPostView(CreateView):
model = ForumPost
fields = ['title', 'body', 'author']
template_name = 'forumpost-add.html'
class AddForumPostView(CreateView):
model = ForumPost
fields = ['title', 'body', 'author']
template_name = 'forumpost-add.html'
No preview for this file type
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