Commit d6606b32 authored by Mario Franco C. Deuna's avatar Mario Franco C. Deuna

Added forms.py, updated views.py and urls.py and added template file post_add.html.

parent 9433b591
from django.forms import ModelForm
from .models import Post
class PostForm(ModelForm):
class Meta:
model = Post
fields = ["post_title", "post_body", "author"]
<form method="post">
{% csrf_token %}
{{form}}
<input type="submit" value="Save Post">
</form>
<a href="{% url 'forum:post-list' %}"><button>Back to Forum</button></a>
...@@ -26,4 +26,7 @@ ...@@ -26,4 +26,7 @@
</p> </p>
{% endif %} {% endif %}
<a href="{% url 'forum:post-add' %}"><button>New Forum Post</button></a>
{% endblock content %} {% endblock content %}
from django.urls import path from django.urls import path
from .views import ForumListView, ForumDetailView from .views import ForumListView, ForumDetailView, PostCreate
urlpatterns = [ urlpatterns = [
path('', ForumListView.as_view(), name='post-list'), path('', ForumListView.as_view(), name='post-list'),
path('<int:pk>/details/', ForumDetailView.as_view(), name='forum-detail'), path('<int:pk>/details/', ForumDetailView.as_view(), name='forum-detail'),
path("add/", PostCreate, name = 'post-add')
] ]
......
from django.shortcuts import render from django.shortcuts import render, redirect
from django.http import Http404, HttpRequest, HttpResponse from django.http import Http404, HttpRequest, HttpResponse
from .models import Post, Reply from .models import Post, Reply
from homepage.models import WidgetUser from homepage.models import WidgetUser
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from .forms import PostForm
#def get_reply(): #def get_reply():
# #
...@@ -81,6 +82,6 @@ def PostCreate(request): ...@@ -81,6 +82,6 @@ def PostCreate(request):
form = PostForm(request.POST) form = PostForm(request.POST)
if form.is_valid(): if form.is_valid():
form.save() form.save()
return redirect('/posts') return redirect('/forum')
return render(request, 'Forum/post_add.html', context) return render(request, 'Forum/post_add.html', context)
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