Commit 5f7610d6 authored by Michael Lopez's avatar Michael Lopez

Merge branch 'announcements_board' into 'master'

Announcements board

See merge request !3
parents a3790519 c71e66c7
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction
# Register your models here. class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ["title", "body", "author"]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ["announcement", "name", "tally"]
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
# Generated by Django 4.1.7 on 2023-03-05 09:23
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(max_length=50)),
('body', models.TextField(max_length=1024)),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, 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(choices=[('like', 'Like'), ('love', 'Love'), ('angry', 'Angry')], default='like', max_length=5)),
('tally', models.IntegerField()),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
from django.db import models from django.db import models
from dashboard.models import WidgetUser
class Announcement(models.Model):
title = models.CharField(max_length=50)
body = models.TextField(max_length=1024)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.title
class Reaction(models.Model):
LIKE = 'Like'
LOVE = 'Love'
ANGR = 'Angry'
namechoices = [
(LIKE, 'Like'),
(LOVE, 'Love'),
(ANGR, 'Angry')
]
name = models.CharField(
max_length=5,
choices=namechoices,
)
tally = models.IntegerField()
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return self.name
# Create your models here.
from django.shortcuts import render from .models import Announcement, Reaction
from django.http import HttpResponse from django.http import HttpResponse
def pageview(request): def pageview(request):
return HttpResponse() announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
string_builder = "Widget's Announcement Board <br> <br> Announcements: <br> "
for announcement in announcements:
string_builder = "{} <br> {} by {} published {} <br> {}".format(
string_builder, announcement.title, announcement.author,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"),
announcement.body
)
for reaction in reactions:
if reaction.announcement == announcement:
string_builder = "{} <br> {}: {}".format(string_builder, reaction.name, reaction.tally)
string_builder += "<br>"
return HttpResponse(string_builder)
<p>Widget's Calendar of Activities<br><br></p> <p>Widget's Calendar of Activities<br /><br /></p>
{% for event in events %} {% for event in events %}
<p> <p>
Date and Time: {{ event.target_datetime }}<br> {{ event.target_datetime }}<br />
Activity: {{ event.activity }}<br> Activity: {{ event.activity }}<br />
Estimated Hours: {{ event.estimated_hours }}<br> Estimated Hours: {{ event.estimated_hours }}<br />
Course/Section: {{ event.course }}<br> Course/Section: {{ event.course }}<br />
Mode: {{ event.location.mode }}<br> Mode: {{ event.location.mode }}<br />
Venue: {{ event.location.venue }} Venue: {{ event.location.venue }}
</p> </p>
{% endfor %} {% endfor %}
...@@ -84,7 +84,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -84,7 +84,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC' TIME_ZONE = 'Asia/Manila'
USE_I18N = True USE_I18N = True
...@@ -93,5 +93,4 @@ USE_TZ = True ...@@ -93,5 +93,4 @@ USE_TZ = True
STATIC_URL = 'static/' STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
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