Created ForumPostUpdateView and forumpost-edit.html

parent d95510dc
......@@ -14,7 +14,8 @@ class ForumPost(models.Model):
on_delete=models.CASCADE,
)
pub_datetime = models.DateTimeField(
default = datetime.now(),
default=datetime.now(),
editable=False,
)
def __str__(self):
......
......@@ -16,4 +16,4 @@
</ul>
<hr>
<button onclick="window.location.href='{% url 'forum:forumpost-add' %}';"> New Post </button>
{% endblock %}4
\ No newline at end of file
{% endblock %}
\ No newline at end of file
......@@ -3,13 +3,13 @@
{% block title %} Add Post {% endblock %}
{% block heading %}
<h1> Add a new post: </h1>
<h1> Add a new Post: </h1>
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div class="separator-bar"></div><br>
<br>
<input type="submit" value="Save New Post">
</form>
{% endblock %}
\ No newline at end of file
......@@ -18,4 +18,5 @@
<br>
{% endfor %}
<hr>
<button onclick="window.location.href='{% url 'forum:forumpost-edit' pk=object.pk %}';"> Edit Post </button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Post {% endblock %}
{% block heading %}
<h1> Edit Post: </h1>
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<br>
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
# forum/urls.py
from django.urls import path
from .views import index, ForumPostDetailView, ForumPostCreateView
from .views import index, ForumPostDetailView, ForumPostCreateView, ForumPostUpdateView
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'),
path('forumposts/<int:pk>/edit', ForumPostUpdateView.as_view(), name='forumpost-edit'),
]
# This might be needed, depending on your Django version
......
......@@ -20,3 +20,8 @@ class ForumPostCreateView(CreateView):
model = ForumPost
template_name = 'forum/forumpost-add.html'
fields = ["title", "body", "author"]
class ForumPostUpdateView(UpdateView):
model = ForumPost
template_name = 'forum/forumpost-edit.html'
fields = '__all__'
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