Commit ffaa93d0 authored by Andre Matthew Dumandan's avatar Andre Matthew Dumandan 😴
parents 79b2a22e 8ff26d55
from django import forms
from .models import Post
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ['post_title', 'post_body', 'author']
\ No newline at end of file
from django.urls import path
from .views import post_list_view, post_detail_view
from .views import post_list_view, post_detail_view, post_create_view
urlpatterns = [
path('', post_list_view, name='post-list'),
path('', post_list_view.as_view(), name='post-list'),
path('posts/<int:post_id>/details', post_detail_view, name='post-details'),
path('posts/add', post_create_view.as_view(), name='post-create')
]
app_name = 'forum'
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views import View
from django.views.generic.edit import CreateView
from .models import Post, Reply
def post_list_view(request):
context = {}
context['post_list'] = Post.objects.order_by('-pub_date').all()
return render(request, 'forum/forum_list.html', context)
class post_list_view(View):
def get(self, request):
post_list = Post.objects.order_by('-pub_date').all()
return render(request, 'forum/forum_list.html', {
"post_list" : post_list
})
def post_detail_view(request, post_id):
post = Post.objects.get(id=post_id)
......@@ -18,3 +17,9 @@ def post_detail_view(request, post_id):
'reply_list': reply_list
}
return render(request, 'forum/forum_details.html', context)
class post_create_view(CreateView):
model = Post
fields = '__all__'
success_url = '/forum/'
\ No newline at end of file
* {
font-family: 'Futura';
text-align: center;
}
header {
color: white;
background-color: #9BB8ED;
font-size: 50px;
text-align: center;
}
body {
background-color: #FFDDE4;
}
label {
color: #A39FE1;
font-size: 25px;
}
#submit_button {
color: white;
background-color: #9BB8ED;
font-size: 15px;
}
a:link {
padding: 5px;
text-decoration: none;
border-style: dotted;
background-color: #9BB8ED;
}
* {
font-family: 'Futura';
}
.center {
display: block;
margin-left: auto;
......@@ -7,31 +10,27 @@
h1 {
color: cornflowerblue;
font-family: 'Futura';
text-align: center;
}
h3 {
color: rgb(45, 101, 205);
font-family: 'Futura';
text-align: center;
}
h4 {
color: black;
font-family: 'Futura';
text-align: center;
font-weight: 200;
}
.replies {
text-align: left;
font-family: 'Futura';
}
h2 {
font-size: 22px;
color: rgb(94, 214, 218);
color: darkslateblue;
}
li {
......@@ -40,10 +39,17 @@ li {
}
p {
color: darkslategrey;
color: darkslateblue;
font-size: 14px;
}
#backtoforum a:link {
padding: 5px;
text-decoration: none;
border-style: dotted;
background-color: cornflowerblue;
}
body {
background-color: rgb(221, 249, 249);
background-color: #c2c0ef;
}
\ No newline at end of file
* {
text-align: center;
font-family: 'Futura';
}
header {
color: white;
background-color: pink;
font-family: 'Futura';
font-size: 50px;
text-align: center;
}
h1 {
color: rgb(94, 214, 218);
font-family: 'Futura';
text-align: center;
}
li {
color: cornflowerblue;
font-family: 'Futura';
font-size: 18px;
text-align: center;
}
a:link {
color: cornflowerblue;
}
a:visited {
color: black;
color: rgb(81, 116, 182);
}
#addnewpost a:link {
padding: 5px;
text-decoration: none;
border-style: dotted;
background-color: rgb(94, 214, 218);
}
body {
......
......@@ -17,7 +17,7 @@
{{ form.announcement_title }}<br><br>
<label for="{{ form.announcement_body.id_for_label }}">Announcement Body</label><br>
{{ form.announcement_body }}<br><br>
<label for="{{ form.authot.id_for_label }}">Author</label><br>
<label for="{{ form.author.id_for_label }}">Author</label><br>
{{ form.author }}<br><br>
<input type="submit" value="Save Announcement" id="submit_button">
</form>
......
......@@ -35,5 +35,8 @@
<p>{{ reply.reply_body }}</p>
{% endfor %}
</div>
<div id = "backtoforum">
<p><a href="{% url 'forum:post-list' %}">Back to main forum</a></p>
</div>
</body>
{% endblock %}
\ No newline at end of file
......@@ -16,5 +16,8 @@
</a>
</li>
{% endfor %}
<div id="addnewpost">
<p><a href="{% url 'forum:post-create' %}">New Forum Post</a></p>
</div>
</body>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Create Post{% endblock %}
{% block styles %} <link rel="stylesheet" href="{% static 'forum/css/forum_create_styles.css' %}"> {% endblock %}
{% block content %}
<body>
<header>New Forum Post</header>
<br>
<form method="POST" action="">
{% csrf_token %}
<label for="{{ form.post_title.auto_id }}">Title</label>
<br>
{{ form.post_title }}
<br>
<label for="{{ form.post_body.auto_id }}">Body</label>
<br>
{{ form.post_body }}
<br>
<label for="{{ form.author.auto_id }}">Author</label>
<br>
{{ form.author }}
<br><br>
<input type="submit" value="Save Post" id="submit_button" href="{% url 'forum:post-list' %}">
<br>
</form>
<br>
<p><a href="{% url 'forum:post-list' %}">Back to main forum</a></p>
</body>
{% endblock %}
\ 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