Commit b7fbdb81 authored by Mavrick Jordan Lee's avatar Mavrick Jordan Lee

Merged dashboard_branch and announcements_branch. Imported Dashboard...

Merged dashboard_branch and announcements_branch. Imported Dashboard WidgetUser Model to Announcements Model for Foreign Key.
parents a323e378 438c1106
from django.contrib import admin
from .models import Announcement, Reaction
# Register your models here.
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('announcement_title', 'announcement_body', 'announcement_pub_datetime')
search_fields = ('announcement_title',)
list_filter = ('announcement_title',)
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('reaction_name', 'reaction_tally', 'reaction_announcement',)
search_fields = ('reaction_name',)
list_filter = ('reaction_name',)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
from django.apps import AppConfig
class AnnouncementsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcements'
# Generated by Django 3.2 on 2023-03-05 07:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('announcement_title', models.CharField(max_length=50, null=True, unique=True)),
('announcement_body', models.CharField(max_length=250, null=True, unique=True)),
('announcement_pub_datetime', models.DateTimeField(null=True)),
],
),
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=50, null=True)),
('reaction_tally', models.IntegerField(null=True)),
('reaction_announcement', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
# Generated by Django 3.2 on 2023-03-05 09:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='reaction_name',
field=models.CharField(blank=True, choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=50, null=True),
),
migrations.AlterField(
model_name='reaction',
name='reaction_tally',
field=models.IntegerField(default=0, null=True),
),
]
# Generated by Django 4.1.7 on 2023-03-06 07:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcements', '0002_auto_20230305_1707'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='announcement_author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
]
from django.db import models
from dashboard.models import WidgetUser
# Create your models here.
# please insert foreign key from dashboard application on announcement_author
class Announcement(models.Model):
announcement_title = models.CharField(max_length=50, unique=True, null=True, )
announcement_body = models.CharField(max_length=250, unique=True, null=True, )
announcement_author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE, null=True)
announcement_pub_datetime = models.DateTimeField(null=True, )
def __str__(self):
return self.announcement_title
reaction_choices = (
('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry'),
)
class Reaction(models.Model):
reaction_name = models.CharField(max_length=50, blank=True, choices=reaction_choices, null=True,)
reaction_tally = models.IntegerField(null=True, default=0, )
reaction_announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True, )
def __str__(self):
return self.reaction_name
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path('', views.announcements, name="announcements")
]
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def announcements(request):
announcement = Announcement.objects.all()
response = "<h2>Widget's Announcement Board</h2>"
for every in announcement:
datetime = every.announcement_pub_datetime.strftime("%a, %b %d, %Y %I:%M %p")
response += "<h3>{}</h3>".format(every.announcement_title) +\
"<p>By --insert foreign name-- published {}</p>".format(datetime)
like_on_post = 0
love_on_post = 0
angry_on_post = 0
reactions = Reaction.objects.filter(reaction_announcement=every)
for every in reactions:
if every.reaction_name == "Like":
like_on_post = every.reaction_tally
elif every.reaction_name == "Love":
love_on_post = every.reaction_tally
elif every.reaction_name == "Angry":
angry_on_post = every.reaction_tally
response += "<p>like: {}".format(like_on_post) +\
"<br>love: {}".format(love_on_post) +\
"<br>angry: {}</p>".format(angry_on_post)
return HttpResponse(response)
...@@ -32,6 +32,7 @@ ALLOWED_HOSTS = [] ...@@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [ INSTALLED_APPS = [
'dashboard.apps.DashboardConfig', 'dashboard.apps.DashboardConfig',
'announcements',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
......
...@@ -19,4 +19,5 @@ from django.urls import path, include ...@@ -19,4 +19,5 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('dashboard/', include("dashboard.urls")), path('dashboard/', include("dashboard.urls")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('announcements/', include("announcements.urls"))
] ]
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