Commit 6ec76bcb authored by Calvin Josh Cruz's avatar Calvin Josh Cruz

Merge branch 'forum' into 'master'

Forum

See merge request midterm_quintupoltrobol!5
parents 5f7610d6 6c895ef8
# Generated by Django 4.1.7 on 2023-03-05 19:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=5),
),
]
from django.contrib import admin from django.contrib import admin
# Register your models here. from .models import ForumPost, Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ["title", "body", "author"]
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ["body", "author", "forumpost"]
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
# Register your models here.
\ No newline at end of file
# Generated by Django 4.1.7 on 2023-03-05 19:50
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
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()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
('forumpost', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost')),
],
),
]
from django.db import models 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):
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
forumpost = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
def __str__(self):
return self.body
# Create your models here. # Create your models here.
from django.shortcuts import render from django.shortcuts import render
from .models import ForumPost, Reply
from django.http import HttpResponse from django.http import HttpResponse
def pageview(request): def pageview(request):
return HttpResponse() forumposts = ForumPost.objects.all()
replys = Reply.objects.all()
string_builder = "Widget's Forum <br> <br> Forum Posts: <br> "
for forumpost in forumposts:
string_builder = "{} <br> {} by {} posted {} <br> {}".format(
string_builder, forumpost.title, forumpost.author,
forumpost.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"), forumpost.body
)
for reply in replys:
if reply.forumpost == forumpost:
string_builder = "{} <br> Reply by {} posted {} <br> {}".format(
string_builder, reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"), reply.body
)
string_builder += "<br>"
return HttpResponse(string_builder)
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