Commit 9dd377bb authored by Migs Atienza's avatar Migs Atienza

Added forumpost-details.html (but error in pks)

parent 069c0f7f
No preview for this file type
from django.db import models
from django.urls import reverse
class ForumPost(models.Model):
title = models.CharField(max_length=100)
......@@ -10,6 +10,9 @@ class ForumPost(models.Model):
def __str__(self):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('forum:forumpost-details', kwargs={'pk': self.pk})
class Reply(models.Model):
body = models.TextField(max_length=1000)
......
......@@ -5,7 +5,7 @@
<h1>Welcome to Widget's Forum!</h1>
<h3>
{% for post in forumposts %}
<a href="{{ forum.get_absolute_url }}">{{ post.title }} by {{ post.author }}</a><br>
<a href="{{ post.get_absolute_url }}">{{ post.title }} by {{ post.author }}</a><br>
{% endfor %}
</h3>
{% endblock %}
......
{% extends 'base.html' %}
{% block title %}{{ reply.forum_post.title }}{% endblock %}
{% block content %}
<h1>{{ reply.forum_post.title }}</h1>
<h3>by {{ reply.forum_post.author }}<br>
{{ reply.forum_post.pub_datetime }}<br>
{{ reply.forum_post.body }}<br>
</h3>
<br>
<h1>POST REPLIES</h1>
<h3>
by {{ reply.author }}
{{ reply.pub_datetime }}
{{ reply.body }}
</h3>
{% endblock %}
{% block scripts %}
<a href="/forum/forumposts{{ reply.forum_post.pk }}/edit"><input type="submit" value="Edit Post"></a>
{% endblock %}
\ No newline at end of file
from django.contrib import admin
from django.urls import path
from .views import index
from .views import index, ForumPostDetailView
urlpatterns = [
path('', index, name='index'),
path('forumposts/<int:pk>/details', ForumPostDetailView.as_view(), name='forumpost-details'),
]
app_name = "forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import ForumPost, Reply
......@@ -7,4 +9,11 @@ from .models import ForumPost, Reply
def index(request):
return render(request, 'forum/forum.html', {'forumposts': ForumPost.objects.all()})
class ForumPostDetailView(DetailView):
model = Reply
def get(self, request, pk):
return render(request, 'forum/forumpost-details.html', {'reply': self.model.objects.get(pk=pk)})
# 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