Created ForumPostCreateView and forumpost-add.html

parent 88a544bc
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from django.db import models from django.db import models
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
from django.urls import reverse from django.urls import reverse
from datetime import datetime
class ForumPost(models.Model): class ForumPost(models.Model):
title = models.CharField(max_length=100) title = models.CharField(max_length=100)
...@@ -12,7 +13,9 @@ class ForumPost(models.Model): ...@@ -12,7 +13,9 @@ class ForumPost(models.Model):
default=True, default=True,
on_delete=models.CASCADE, on_delete=models.CASCADE,
) )
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField(
default = datetime.now(),
)
def __str__(self): def __str__(self):
return self.title return self.title
......
...@@ -14,4 +14,6 @@ ...@@ -14,4 +14,6 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} <hr>
\ No newline at end of file <button onclick="window.location.href='{% url 'forum:forumpost-add' %}';"> New Post </button>
{% endblock %}4
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Post {% endblock %}
{% block heading %}
<h1> Add a new post: </h1>
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div class="separator-bar"></div><br>
<input type="submit" value="Save New Post">
</form>
{% endblock %}
\ No newline at end of file
...@@ -17,4 +17,5 @@ ...@@ -17,4 +17,5 @@
<p> {{ reply.body }} </p> <p> {{ reply.body }} </p>
<br> <br>
{% endfor %} {% endfor %}
<hr>
{% endblock %} {% endblock %}
\ No newline at end of file
# forum/urls.py # forum/urls.py
from django.urls import path from django.urls import path
from .views import index, ForumPostDetailView from .views import index, ForumPostDetailView, ForumPostCreateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('forumposts/<int:pk>/details', ForumPostDetailView.as_view(), name='forumpost-details'), path('forumposts/<int:pk>/details', ForumPostDetailView.as_view(), name='forumpost-details'),
path('forumposts/add', ForumPostCreateView.as_view(), name='forumpost-add'),
] ]
# This might be needed, depending on your Django version # This might be needed, depending on your Django version
......
...@@ -15,3 +15,8 @@ def index(request): ...@@ -15,3 +15,8 @@ def index(request):
class ForumPostDetailView(DetailView): class ForumPostDetailView(DetailView):
model = ForumPost model = ForumPost
template_name = 'forum/forumpost-details.html' template_name = 'forum/forumpost-details.html'
class ForumPostCreateView(CreateView):
model = ForumPost
template_name = 'forum/forumpost-add.html'
fields = ["title", "body", "author"]
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