Created ForumPostCreateView and forumpost-add.html

parent 88a544bc
......@@ -2,6 +2,7 @@
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
from datetime import datetime
class ForumPost(models.Model):
title = models.CharField(max_length=100)
......@@ -12,7 +13,9 @@ class ForumPost(models.Model):
default=True,
on_delete=models.CASCADE,
)
pub_datetime = models.DateTimeField()
pub_datetime = models.DateTimeField(
default = datetime.now(),
)
def __str__(self):
return self.title
......
......@@ -14,4 +14,6 @@
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
<hr>
<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 @@
<p> {{ reply.body }} </p>
<br>
{% endfor %}
<hr>
{% endblock %}
\ No newline at end of file
# forum/urls.py
from django.urls import path
from .views import index, ForumPostDetailView
from .views import index, ForumPostDetailView, ForumPostCreateView
urlpatterns = [
path('', index, name='index'),
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
......
......@@ -15,3 +15,8 @@ def index(request):
class ForumPostDetailView(DetailView):
model = ForumPost
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