Commit 65381896 authored by Eldon Dagdag's avatar Eldon Dagdag

Created forum app and models

parent 1f9aed7e
File added
...@@ -15,4 +15,4 @@ def index(request): ...@@ -15,4 +15,4 @@ def index(request):
return_string += '</p>' return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string) html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string) return HttpResponse(return_string)
\ No newline at end of file \ No newline at end of file
from django.contrib import admin
from .models import ForumPost, Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
class ReplyAdmin(admin.ModelAdmin):
model = Reply
# Register your models here.
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 4.1.7 on 2023-03-05 15:45
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(default='', max_length=255)),
('body', models.TextField(default='')),
('author', models.CharField(default='', max_length=255)),
('pub_datetime', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField(default='')),
('author', models.CharField(default='', max_length=255)),
('pub_datetime', models.DateTimeField(auto_now=True)),
],
),
]
# Generated by Django 4.1.7 on 2023-03-05 16:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('forum', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
]
# Generated by Django 4.1.7 on 2023-03-05 16:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0002_alter_forumpost_author_alter_reply_author'),
]
operations = [
migrations.AlterField(
model_name='forumpost',
name='pub_datetime',
field=models.DateTimeField(),
),
migrations.AlterField(
model_name='reply',
name='pub_datetime',
field=models.DateTimeField(),
),
]
# Generated by Django 4.1.7 on 2023-03-05 16:39
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0003_alter_forumpost_pub_datetime_and_more'),
]
operations = [
migrations.AddField(
model_name='reply',
name='reply',
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost'),
),
]
# Generated by Django 4.1.7 on 2023-03-05 16:40
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('forum', '0004_reply_reply'),
]
operations = [
migrations.RenameField(
model_name='reply',
old_name='reply',
new_name='reply_to',
),
]
from django.db import models
from dashboard import models as dashboard_models
class ForumPost(models.Model):
title = models.CharField(max_length=255, default='')
body = models.TextField(default='')
author = models.ForeignKey(dashboard_models.WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField(auto_now=False, auto_now_add=False)
def __str__(self):
return '{} by {} on {}'.format(self.title, self.author, self.pub_datetime.strftime("%m/%d/%Y %I:%M %p"))
class Reply(models.Model):
reply_to = models.ForeignKey(ForumPost, on_delete=models.CASCADE, default='')
body = models.TextField(default='')
author = models.ForeignKey(dashboard_models.WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField(auto_now=False, auto_now_add=False)
def __str__(self):
return 'Reply by {} on {}'.format(self.author, self.pub_datetime.strftime("%m/%d/%Y %I:%M %p"))
# Create your models here.
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
from .models import Reply
def index(request):
return_string = "<p>Widget's Forum</p> <p>Forum Posts:<br>"
for post in ForumPost.objects.all():
post_string = '{} by {} {} posted {}:<br>'.format(
post.title, post.author.first_name, post.author.last_name,
post.pub_datetime.strftime("%m/%d/%Y %I:%M %p")
)
post_string += '{}<br>'.format(post.body)
return_string += post_string
for reply in Reply.objects.all():
if post == reply.reply_to:
reply_string = 'Reply by {} {} posted {}:<br>'.format(
reply.author.first_name, reply.author.last_name,
reply.pub_datetime.strftime("%m/%d/%Y %I:%M %p")
)
reply_string += '{}<br>'.format(reply.body)
return_string += reply_string
return_string += '<br>'
return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(return_string)
# Create your views here.
...@@ -43,7 +43,7 @@ INSTALLED_APPS = [ ...@@ -43,7 +43,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dashboard', 'dashboard',
#for announcement board #for announcement board
#for forum 'forum',
#for assignments #for assignments
#for calendar #for calendar
] ]
......
...@@ -20,7 +20,7 @@ urlpatterns = [ ...@@ -20,7 +20,7 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('dashboard/', include('dashboard.urls', namespace='dashboard')), path('dashboard/', include('dashboard.urls', namespace='dashboard')),
#for announcement board #for announcement board
#for forum path('forum', include('forum.urls', namespace='forum')),
#for assignments #for assignments
#for calendar #for calendar
] ]
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