Commit a84414b2 authored by Mary Adelaide A. Salto's avatar Mary Adelaide A. Salto
parents df45badf ba36e438
File added
widget_CtrlF/.DS_Store
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')
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
from django.apps import AppConfig
class ForumConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forum'
# Generated by Django 3.2 on 2023-03-05 01:32
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='ForumPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('body', models.TextField()),
('author', models.CharField(max_length=50)),
('pub_datetime', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('author', models.CharField(max_length=50)),
('pub_datetime', models.DateTimeField()),
],
),
]
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()
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "forum"
\ No newline at end of file
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)
...@@ -43,6 +43,7 @@ INSTALLED_APPS = [ ...@@ -43,6 +43,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dashboard', 'dashboard',
'announcement_board', 'announcement_board',
'forum',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,11 +14,11 @@ Including another URLconf ...@@ -14,11 +14,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import include, path
from django.urls import path, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('announcement_board/', include('announcement_board.urls', namespace='announcement_board')), path('announcement_board/', include('announcement_board.urls', namespace='announcement_board')),
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('forum/', include('forum.urls', namespace="forum")),
] ]
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