Commit fdbb6f84 authored by Migs Atienza's avatar Migs Atienza

Added forumpost-add.html

parent 9dd377bb
No preview for this file type
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
class ForumPost(models.Model): class ForumPost(models.Model):
title = models.CharField(max_length=100) title = models.CharField(max_length=100)
body = models.TextField(max_length=1000) body = models.TextField(max_length=1000)
...@@ -22,4 +23,6 @@ class Reply(models.Model): ...@@ -22,4 +23,6 @@ class Reply(models.Model):
def __str__(self): def __str__(self):
return '{}\'s reply to {}'.format(self.author, self.forum_post) return '{}\'s reply to {}'.format(self.author, self.forum_post)
# Create your models here. # Create your models here.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</h3> </h3>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<a href="/forum/forumposts/add"><input type="submit" value="New Post"></a><br><br>
<a href="/dashboard">Dashboard</a><br> <a href="/dashboard">Dashboard</a><br>
<a href="/announcement">Announcements</a><br> <a href="/announcement">Announcements</a><br>
<a href="/assignments">Assignments</a><br> <a href="/assignments">Assignments</a><br>
......
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block content %}
<h1>Add a new Post:</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Post">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from .views import index, ForumPostDetailView 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'),
] ]
app_name = "forum" app_name = "forum"
\ No newline at end of file
...@@ -16,4 +16,16 @@ class ForumPostDetailView(DetailView): ...@@ -16,4 +16,16 @@ class ForumPostDetailView(DetailView):
def get(self, request, pk): def get(self, request, pk):
return render(request, 'forum/forumpost-details.html', {'reply': self.model.objects.get(pk=pk)}) return render(request, 'forum/forumpost-details.html', {'reply': self.model.objects.get(pk=pk)})
class ForumPostCreateView(CreateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class ForumPostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
# Create your views here. # Create your views here.
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