Commit cfe49dca authored by Chino Tesoro's avatar Chino Tesoro

updated models and views for forum

parent 7ccc0b38
from django.contrib import admin from django.contrib import admin
from .models import Post from .models import Post
admin.site.register(Post) admin.site.register(Post)
\ No newline at end of file
from .models import Reply
admin.site.register(Reply)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-04 13:15
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
('forum', '0003_delete_reaction'),
]
operations = [
migrations.AddField(
model_name='post',
name='author',
field=models.ForeignKey(default=100, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
preserve_default=False,
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.CharField(max_length=99999)),
('pub_date', models.DateTimeField(verbose_name='date published')),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
]
from django.db import models from django.db import models
from homepage.models import WidgetUser
class Post (models.Model): class Post (models.Model):
post_title = models.CharField(max_length=99999) post_title = models.CharField(max_length=99999)
post_body = models.CharField(max_length=99999) post_body = models.CharField(max_length=99999)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return self.post_title return f"{self.post_title} {self.post_body} {self.pub_date}"
class Reply (models.Model):
reply_body = models.CharField(max_length=99999)
pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
def __str__(self):
return f"{self.reply_body} {self.pub_date}"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
posts = Post.objects.all()
replies = Reply.objects.all()
finalstring = "FORUM POSTS:<br />"
for i in posts:
poststring = f"{i.post_title} by " + f"{i.author} dated " + f"{i.pub_date}:<br />" + f"{i.post_body}<br />"
finalstring += poststring
for i in replies:
replystring = "Reply by " + f"{i.author} dated " + f"{i.pub_date}:<br \>" + f"{i.reply_body}<br />"
finalstring += replystring
def index (request): def index (request):
return HttpResponse ("Welcome to Widget's Forum!") return HttpResponse (finalstring)
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