Commit d73659ee authored by Eury See's avatar Eury See

Edited the links to the pages' buttons and fixed minor details.

parent e8f4b864
...@@ -20,16 +20,16 @@ ...@@ -20,16 +20,16 @@
<p1>Forum posts:</p1> <p1>Forum posts:</p1>
{% for post in posts %} {% for post in posts %}
<li><a href="{% url 'Forum:forumpost-details' pk=post.pk %}">{{post.title}} by {{post.author}}</a></li> <li><a href="{% url 'Forum:forumpost-details' pk=post.pk %}">{{ post.title }} by {{ post.author }}</a></li>
{% endfor %} {% endfor %}
<br> <br>
<form method="post"> <button type="submit">
{% csrf_token %} <a href="{% url 'Forum:forumpost-add' %}">New Post</a>
{{form.as_p}} </button>
<button type="submit">New Post</button>
</form> <br>
<br>
<a href="http://127.0.0.1:8000/Dashboard/dashboard">Dashboard</a> <a href="http://127.0.0.1:8000/Dashboard/dashboard">Dashboard</a>
<br> <br>
<a href="http://127.0.0.1:8000/Announcements/announcements">Announcements</a> <a href="http://127.0.0.1:8000/Announcements/announcements">Announcements</a>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<br> <br>
{{ object.body }} {{ object.body }}
<p>Post Replies:</p> <h2>Post Replies:</h2>
{% for reply in replies %} {% for reply in replies %}
by {{ reply.author }} by {{ reply.author }}
{{ reply.pub_datetime }} {{ reply.pub_datetime }}
...@@ -29,12 +29,13 @@ ...@@ -29,12 +29,13 @@
No replies yet. No replies yet.
{% endfor %} {% endfor %}
<form method="post"> <br>
{% csrf_token %} <br>
<br><button type="submit"> <button type="submit">
Edit Post <a href="{% url 'Forum:forumpost-edit' pk=forumpost.pk %}">Edit Post</a>
</button> </button>
</form> </form>
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import ( from .views import (
index, forum, ForumDetailView, AddForumPostView, EditForumPostView) index, forum, ForumDetailView, AddForumPostView,
EditForumPostView, ForumListView)
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path('forum/', forum, name='forum'), path('forum/', ForumListView.as_view(), name='forum'),
path('forum/forumposts/<int:pk>/details/', ForumDetailView.as_view(), name='forumpost-details'), path('forum/forumposts/<int:pk>/details/', ForumDetailView.as_view(), name='forumpost-details'),
path('forum/forumposts/add/', AddForumPostView.as_view(), name='forumpost-add'), path('forum/forumposts/add/', AddForumPostView.as_view(), name='forumpost-add'),
path('forum/forumposts/<pk>/edit/', EditForumPostView.as_view(), name = 'forumpost-edit'), path('forum/forumposts/<pk>/edit/', EditForumPostView.as_view(), name = 'forumpost-edit'),
......
...@@ -4,6 +4,7 @@ from django.views import View ...@@ -4,6 +4,7 @@ from django.views import View
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
from django.views.generic.edit import UpdateView from django.views.generic.edit import UpdateView
from django.views.generic.list import ListView
from .models import ForumPost, Reply from .models import ForumPost, Reply
...@@ -24,6 +25,12 @@ def forum(request): ...@@ -24,6 +25,12 @@ def forum(request):
context = {'posts': posts} context = {'posts': posts}
return render(request, 'forum.html', context) return render(request, 'forum.html', context)
class ForumListView(ListView):
model = ForumPost
template_name = 'forum.html'
context_object_name = 'posts'
ordering = ['-pub_datetime'] # sort by newest to oldest
class ForumDetailView(DetailView): class ForumDetailView(DetailView):
model = ForumPost model = ForumPost
template_name = 'forumpost-details.html' template_name = 'forumpost-details.html'
......
No preview for this file type
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