Commit 2972cd28 authored by Alliyah Marcelo's avatar Alliyah Marcelo

Final commit.

parent 991f5c63
...@@ -41,4 +41,4 @@ class ReplyAdmin(admin.ModelAdmin): ...@@ -41,4 +41,4 @@ class ReplyAdmin(admin.ModelAdmin):
admin.site.register(ForumPost, ForumPostAdmin) admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin) admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
...@@ -10,7 +10,7 @@ class ForumPost(models.Model): ...@@ -10,7 +10,7 @@ class ForumPost(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='forumpost_author' related_name='forumpost_author'
) )
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField(auto_now=True)
def __str__(self): def __str__(self):
return '{} by {} posted {}: {}'.format( return '{} by {} posted {}: {}'.format(
...@@ -46,4 +46,4 @@ class Reply(models.Model): ...@@ -46,4 +46,4 @@ class Reply(models.Model):
self.author, self.author,
self.pub_datetime, self.pub_datetime,
self.body, self.body,
) )
\ No newline at end of file
...@@ -8,18 +8,19 @@ ...@@ -8,18 +8,19 @@
{% block content %} {% block content %}
<p> <p>
Forum Posts:<br> Forum Posts:<br>
{% for post in posts %} {% for post in posts|slice:"::-1" %}
<a href="{{ post.get_absolute_url }}"> <a href="{{ post.get_absolute_url }}">
{{ post.title }} by {{ post.author }} {{ post.title }} by {{ post.author.first_name }} {{ post.author.last_name }}
</a><br> </a><br>
{% endfor %} {% endfor %}
</p> </p>
{% endblock %} {% endblock %}
{% block footing %} {% block footing %}
<a href="{% url 'forum:forumpost-create' %}"> <a href="{% url 'forum:forumpost-create' %}">
<button class="btn add">New Post</button> <button class="btn add">New Post</button>
</a><br> </a><br><br>
<a href="/dashboard/" class="link">Dashboard</a><br> <a href="/dashboard/" class="link">Dashboard</a><br>
<a href="/announcements/" class="link">Announcements</a><br> <a href="/announcements/" class="link">Announcements</a><br>
......
...@@ -11,11 +11,18 @@ ...@@ -11,11 +11,18 @@
{% block content %} {% block content %}
<p> <p>
by {{ object.author }}<br> by {{ object.author.first_name }} {{ object.author.last_name }}<br>
{{ object.pub_datetime }}<br> {{ object.pub_datetime|date:"m/d/Y" }}, {{ object.pub_datetime|time:"g:iA" }}<br>
{{ object.body }}<br> {{ object.body }}<br>
</p> </p>
{% endblock %} POST REPLIES:<br>
{% for reply in replys %}
{% if reply.forumpost == object %}
by {{ reply.author.first_name }} {{ reply.author.last_name }}<br>
{{ reply.pub_datetime|date:"m/d/Y" }}, {{ reply.pub_datetime|time:"g:iA" }}<br>
{{ reply.body }}<br><br>
{% endif %}
{% endfor %}
{% block footing %} {% block footing %}
<a href="{% url 'forum:forumpost-update' object.pk %}"> <a href="{% url 'forum:forumpost-update' object.pk %}">
......
...@@ -4,7 +4,7 @@ from .views import (forum, ForumPostDetailView, ...@@ -4,7 +4,7 @@ from .views import (forum, ForumPostDetailView,
ForumPostCreateView, ForumPostUpdateView) ForumPostCreateView, ForumPostUpdateView)
urlpatterns = [ urlpatterns = [
path('forum/', forum, name='forum'), path('', forum, name='forum'),
path('forumposts/<int:pk>/details/', path('forumposts/<int:pk>/details/',
ForumPostDetailView.as_view(), ForumPostDetailView.as_view(),
name='forumpost-details'), name='forumpost-details'),
...@@ -16,4 +16,4 @@ urlpatterns = [ ...@@ -16,4 +16,4 @@ urlpatterns = [
name='forumpost-update'), name='forumpost-update'),
] ]
app_name = "forum" app_name = "forum"
\ No newline at end of file
...@@ -2,7 +2,7 @@ from django.shortcuts import render ...@@ -2,7 +2,7 @@ from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, UpdateView
from .models import ForumPost from .models import ForumPost, Reply
def forum(request): def forum(request):
...@@ -14,6 +14,11 @@ class ForumPostDetailView(DetailView): ...@@ -14,6 +14,11 @@ class ForumPostDetailView(DetailView):
model = ForumPost model = ForumPost
template_name = 'forum/forumpost-details.html' template_name = 'forum/forumpost-details.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['replys'] = Reply.objects.all()
return context
class ForumPostCreateView(CreateView): class ForumPostCreateView(CreateView):
model = ForumPost model = ForumPost
......
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