Commit 2714d80c authored by Lance Cedric Tan's avatar Lance Cedric Tan

Created forum app

parent 7b9a1e88
from django.contrib import admin
from .models import ForumPost, Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
search_fields = ('title', 'body', 'author',)
list_display = ('title', 'body', 'author', 'pub_datetime',)
list_filter = ('title', 'author', 'pub_datetime',)
class ReplyAdmin(admin.ModelAdmin):
model = Reply
search_fields = ('body', 'author',)
list_display = ('body', 'author', 'pub_datetime',)
list_filter = ('author', 'pub_datetime')
# Register your models here.
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
from django.db import models
from dashboard.models import WidgetUser
class ForumPost(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.title
class Reply(models.Model):
post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
# Create your models here.
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
# Create your views here.
def index(request):
page_content = "<p>Widget's Forum</> Forum Posts:<br>"
for post in ForumPost.objects.all():
page_content += '{} by {} {} posted {}:<br>{}<br>'.format(
post.title, post.author.first_name, post.author.last_name,
post.pub_datetime.strftime('%m/%d/%Y, %H:%M %p'), post.body
)
for reply in Reply.objects.all():
if reply.post==post.title:
page_content += 'Reply by {} {} posted {}:<br>{}<br>'.format(
reply.author.first_name, reply.author.last_name,
reply.pub_datetime.strftime('%m/%d/%Y, %H:%M %p'),
reply.body
)
return HttpResponse(page_content)
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