Commit 73953eaa authored by Bryan Carlo Guanlao's avatar Bryan Carlo Guanlao

Announcement: models added and modified

added Reaction model, its foreign key and fields for announcement model
parent b99e11d4
from django.contrib import admin
from .models import Announcement
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
......@@ -8,4 +8,10 @@ class AnnouncementAdmin(admin.ModelAdmin):
list_display = ('announcement_title', 'pub_date')
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('reaction_name', 'announcement', 'tally')
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
# Generated by Django 3.2.12 on 2022-03-22 18:58
# Generated by Django 3.2.12 on 2022-04-03 02:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
......@@ -8,6 +9,7 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('homepage', '0001_initial'),
]
operations = [
......@@ -18,6 +20,16 @@ class Migration(migrations.Migration):
('announcement_title', models.CharField(max_length=50)),
('announcement_body', models.TextField(max_length=500)),
('pub_date', models.DateField(auto_now_add=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Hate', 'Hate')], default='Like', max_length=10)),
('tally', models.IntegerField()),
('announcement_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
# Generated by Django 3.2.12 on 2022-04-03 02:55
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='reaction',
old_name='announcement_name',
new_name='announcement',
),
]
from django.db import models
from homepage.models import WidgetUser
REACTION_CHOICES = [('Like', 'Like'), ('Love', 'Love'), ('Hate', 'Hate')]
class Announcement(models.Model):
author = models.ForeignKey(
WidgetUser,
on_delete=models.CASCADE,
)
announcement_title = models.CharField(max_length=50)
announcement_body = models.TextField(max_length=500)
pub_date = models.DateField(auto_now_add=True)
def __str__(self):
return '{}'.format(self.announcement_title)
class Reaction(models.Model):
announcement = models.ForeignKey(
Announcement,
on_delete=models.CASCADE,
)
reaction_name = models.CharField(
max_length=10,
choices=REACTION_CHOICES,
default='Like'
)
tally = models.IntegerField()
def _str_(self):
return '{}: {}'.format(self.reaction_name, self.tally)
# Generated by Django 4.0.3 on 2022-03-22 03:09
# Generated by Django 3.2.12 on 2022-04-03 02:44
from django.db import migrations, models
......
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