Commit 525e556e authored by Norberto Tadeo's avatar Norberto Tadeo 😔

added requirements to forum

parent b8c20f9c
from django.contrib import admin
from .models import Post
from .models import Post, Reply
class ForumAdmin(admin.ModelAdmin):
# Register your models here.
class PostAdmin(admin.ModelAdmin):
model = Post
list_display=('post_title','pub_date','author')
list_filter=('pub_date','post_title','author')
search_fields=('pub_date','post_title',)
list_display=('post_title','pub_date',)
list_filter=('pub_date','post_title',)
admin.site.register(Post, PostAdmin)
admin.site.register(Post, ForumAdmin)
# Register your models here.
class ReplyAdmin(admin.ModelAdmin):
model = Reply
#list_display=('reply_body','pub_date','author')
list_filter=('pub_date','author')
admin.site.register(Reply, ReplyAdmin)
# Generated by Django 4.0.3 on 2022-04-05 07:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0002_rename_forum_post'),
]
operations = [
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=100000)),
('pub_date', models.DateField(auto_now_add=True)),
('active', models.BooleanField(default=True)),
('post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='replies', to='forum.post')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 13:04
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_widgetuser_department'),
('forum', '0003_reply'),
]
operations = [
migrations.AddField(
model_name='post',
name='author',
field=models.ForeignKey(default='', null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='post',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.post'),
),
]
# Generated by Django 4.0.3 on 2022-04-05 13:13
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0006_widgetuser_department'),
('forum', '0004_post_author_alter_reply_post'),
]
operations = [
migrations.AddField(
model_name='reply',
name='author',
field=models.ForeignKey(default='', null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
]
from django.db import models
from homepage.models import WidgetUser
class Post(models.Model):
#Author = WidgetUser.objects.all()
post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=100000)
pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser, null = True, on_delete=models.CASCADE, default = "Anonymous")
def __str__(self):
return'{}: {}'.format(self.post_title,self.pub_date)
class Reply(models.Model):
post = models.ForeignKey(Post, null = True, on_delete=models.CASCADE, default = None)
reply_body = models.CharField(max_length=100000)
pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser, null = True, on_delete=models.CASCADE, default ='Anonymous')
active = models.BooleanField(default=True)
#parent = models.ForeignKey('self', null=True,blank=True,related_name='replies')
#class Meta:
#ordering = ('pub_date')
def __str__(self):
if len(self.reply_body) >= 50:
return 'Reply to ({} | {}) by {} - {}... | {}'.format(self.post.post_title,self.post.pub_date, self.author, self.reply_body[0:50],self.pub_date)
else:
return 'Reply to ({} | {}) by {} - {} | {}'.format(self.post.post_title,self.post.pub_date, self.author, self.reply_body,self.pub_date)
\ No newline at end of file
from django.urls import path
from .views import index
from .views import displayForumPosts
urlpatterns = [
path('', index, name='index')
path('', displayForumPosts, name='displayForumPosts')
]
app_name='forum'
from django.shortcuts import render
from . import models
from asyncio.windows_events import NULL
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Welcome to Widget's Forum!")
def displayForumPosts(request):
ForumPosts = models.Post.objects.all()
ForumReplies = models.Reply.objects.all()
output = ""
for Post in ForumPosts:
P_title = Post.post_title
P_body = Post.post_body
P_pub_date = Post.pub_date
PostThread = ("<br><font size='+1'> Post (" + P_title + ") by " + str(Post.author) + " dated " + str(P_pub_date) + ": <br>" + P_body + "</font>")
output += PostThread + "<br>"
for Reply in ForumReplies:
ReplytoPost = Reply.post.post_title
R_body = Reply.reply_body
R_pub_date = Reply.pub_date
if ReplytoPost == P_title and R_body != NULL:
ReplyThread = (
"<br> Reply to (" + ReplytoPost + ") by " + str(Reply.author) + " dated " + str(R_pub_date) + ": <br>" +
R_body )
output += ReplyThread + "<br>"
return HttpResponse('<h1>FORUM POSTS: </h1>' + output )
\ No newline at end of file
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