Commit 426d6222 authored by Jayson Lim's avatar Jayson Lim

Updated Reaction class attributes and implemented admin panel

parent 91fb39ba
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction
# Register your models here. class ReactionInline(admin.TabularInline):
model = Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'author', )
search_fields = ('title', 'body', 'author', )
list_filter = ('title', 'author')
fieldsets = [
('Announcement', {
'fields':
('title', 'body','author')
})
]
inlines = [ReactionInline]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
# Generated by Django 3.2 on 2023-03-04 07:17
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='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='', max_length=250)),
('body', models.TextField(blank=True, null=True)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
('tally', models.IntegerField(default=0)),
('annoucement', models.ForeignKey(default=True, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='announcementBoard.announcement')),
],
),
]
...@@ -16,8 +16,11 @@ class Announcement(models.Model): ...@@ -16,8 +16,11 @@ class Announcement(models.Model):
return self.title return self.title
class Reaction(models.Model): class Reaction(models.Model):
name = models.CharField(max_length=10, null=False, blank=False) name = models.CharField(max_length=5, choices=[
tally = models.IntegerField(default=0) ('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')], default='Like')
tally = models.PositiveIntegerField(default=0)
annoucement = models.ForeignKey( annoucement = models.ForeignKey(
Announcement, Announcement,
null=True, null=True,
......
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