Created ForumPostUpdateView and forumpost-edit.html

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