added reaction model to announcements app, edited announcement model, edited...

added reaction model to announcements app, edited announcement model, edited admin.py to appear in admin terminal, edited views.py to show changes in browser
parent 21824693
from django.contrib import admin
# Register your models here.
from .models import Announcement
from .models import Announcement, Reaction
admin.site.register(Announcement)
\ No newline at end of file
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement)
admin.site.register(Reaction)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-05 16:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_widgetuser_department_widgetuser_email_and_more'),
('announcements', '0002_rename_announcements_announcement'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=1, 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(max_length=10)),
('tally', models.IntegerField(default=0)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 16:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_announcement_author_reaction'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='announcement',
),
migrations.AddField(
model_name='reaction',
name='announcement',
field=models.ManyToManyField(to='announcements.announcement'),
),
]
# Generated by Django 4.0.3 on 2022-04-05 16:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_remove_reaction_announcement_reaction_announcement'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='announcement',
),
migrations.AddField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement'),
),
]
from multiprocessing import allow_connection_pickling
from django.db import models
from homepage.models import WidgetUser
# Create your models here.
class Announcement(models.Model):
announcement_title = models.CharField(max_length=50)
announcement_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("Date Published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,default = 1)
pub_date = models.DateField("Date Published")
def __str__(self):
return self.announcement_title
\ No newline at end of file
return self.announcement_title
class Reaction(models.Model):
reaction_name = models.CharField(max_length=10)
tally = models.IntegerField(default=0)
announcement = models.ForeignKey(Announcement,on_delete=models.CASCADE, default = 1)
def __str__(self):
return self.reaction_name
\ No newline at end of file
from django.http import HttpResponse
from .models import Announcement, Reaction
text = ""
announcementCounter = 1
reactionCounter = 0
announcementList = Announcement.objects.all()
reactionList = Reaction.objects.all()
outputText = "ANNOUNCEMENTS:"
for i in announcementList:
text += "<br />" + f"{i.announcement_title} by " + f"{i.author} dated " + f"{i.pub_date}:<br />" + f"{i.announcement_body}<br />"
if announcementCounter == 1:
while reactionCounter < 3:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
elif announcementCounter == 2:
while reactionCounter < 6:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
elif announcementCounter == 3:
while reactionCounter < 9:
currentReaction = reactionList[reactionCounter]
text += f"{currentReaction.reaction_name}: " + f"{currentReaction.tally}<br />"
reactionCounter += 1
announcementCounter += 1
outputText += text
# Create your views here.
def index(request):
return HttpResponse("This is the Announcement Board!")
\ No newline at end of file
return HttpResponse(outputText)
\ 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