Commit 26a30abf authored by Trisha Angel Millena's avatar Trisha Angel Millena

Created Edit Post Page: created forumpost-edit.html,edited urls.py, edited views.py

parent 26f955a1
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Post{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }}has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<h1>Edit Post:</h1>
<form method = 'POST'>
{% csrf_token %}
{{ form.as_p }}
<input type = "submit" value = "Save Changes to Post">
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import forum, ForumPostDetailView, ForumPostCreateView from .views import forum, ForumPostDetailView, ForumPostCreateView, ForumPostUpdateView
urlpatterns = [ urlpatterns = [
path('', forum, name = "forum"), path('', forum, name = "forum"),
path("forum/forumposts/<int:pk>/details/", ForumPostDetailView.as_view(), name = "forumpost-details"), path("forum/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")
] ]
app_name = "forum" app_name = "forum"
\ No newline at end of file
...@@ -2,7 +2,7 @@ from django.shortcuts import render ...@@ -2,7 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import ForumPost, Reply from .models import ForumPost, Reply
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView, UpdateView
def forum(request): def forum(request):
posts = ForumPost.objects.all() posts = ForumPost.objects.all()
...@@ -21,3 +21,8 @@ class ForumPostCreateView(CreateView): ...@@ -21,3 +21,8 @@ class ForumPostCreateView(CreateView):
model = ForumPost model = ForumPost
template_name = 'forum/forumpost-add.html' template_name = 'forum/forumpost-add.html'
fields = '__all__' fields = '__all__'
class ForumPostUpdateView(UpdateView):
model = ForumPost
template_name = 'forum/forumpost-edit.html'
fields = '__all__'
\ No newline at end of file
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