Commit 6e0df981 authored by Alliyah Marcelo's avatar Alliyah Marcelo

Configured models and admin panel for the forum app

parent 650cc03a
from django.contrib import admin
# Register your models here.
from .models import ForumPost, Reply
class ReplyInline(admin.TabularInline):
model = Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ('title', 'body', 'author', 'pub_datetime',)
search_fields = ('title', 'author',)
list_filter = ('author', 'pub_datetime',)
inlines = [ReplyInline,]
fieldsets = [
('Forum Data', {
'fields': [
('title', 'body'), 'author', 'pub_datetime'
]
}),
]
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ('body', 'author', 'pub_datetime',)
search_fields = ('author',)
list_filter = ('author', 'pub_datetime',)
fieldsets = [
('Reply Data', {
'fields': [
('body'), 'author', 'pub_datetime'
]
}),
]
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
# Generated by Django 4.1.7 on 2023-03-04 14:16
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, related_name='forumpost_author', 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, related_name='reply_author', to='dashboard.widgetuser')),
('forumpost', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='forumpost_reply', to='forum.forumpost')),
],
),
]
from django.db import models
# Create your models here.
class ForumPost(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
author = models.ForeignKey(
'dashboard.WidgetUser',
on_delete=models.CASCADE,
related_name='forumpost_author'
)
pub_datetime = models.DateTimeField()
def __str__(self):
return '{} by {} posted {}: {}'.format(
self.title,
self.author,
self.pub_datetime,
self.body
)
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey(
'dashboard.WidgetUser',
on_delete=models.CASCADE,
related_name='reply_author'
)
pub_datetime = models.DateTimeField()
forumpost = models.OneToOneField(
ForumPost,
on_delete=models.CASCADE,
related_name='forumpost_reply'
)
def __str__(self):
return 'Reply by {} posted {}: {}'.format(
self.author,
self.pub_datetime,
self.body
)
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
#from .models import ForumPost, Reply
def index(request):
return HttpResponse('Sample muna.')
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