Commit cfaf9aba authored by John Raymon C Yu's avatar John Raymon C Yu

Yu edited assignments

parents f25d2926 2565072e
# Generated by Django 3.2.12 on 2022-05-20 11:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0016_alter_announcement_author'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='announce_image',
field=models.ImageField(blank=True, default='faceless_9ltCukV.png', null=True, upload_to=''),
),
]
...@@ -8,7 +8,7 @@ class Announcement(models.Model): ...@@ -8,7 +8,7 @@ class Announcement(models.Model):
announcement_body = models.CharField(max_length=500) announcement_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
reaction_list = models.ForeignKey('Reaction', on_delete=models.CASCADE, related_name='+', default=1) reaction_list = models.ForeignKey('Reaction', on_delete=models.CASCADE, related_name='+', default=1)
announce_image = models.ImageField(default="faceless_9ltCukV.png", null=True, blank=True)
def __str__(self): def __str__(self):
return self.announcement_title return self.announcement_title
......
h1 {
color: purple;
font-weight:bold;
font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
p {
color: orange;
font-weight:bold;
font-family:'Courier New', Courier, monospace;
}
body {
background-color: beige;
font-family:'Courier New', Courier, monospace;
}
a {
color: orangered;
}
{% extends "announcement/base.html" %}
{% block content %}
<img src="{{announce.announce_image.url}}">
<h1> {{ announce.announcement_title }} </h1>
<p> <em> by {{ announce.author.first_name}} {{announce.author.last_name}}, {{announce.pub_date|date:"d/m/Y h:i:s A"}} </em> </p>
<p> {{announce.announcement_body}}</p>
<ul>
{% for react in reacts %}
<li> {{react.reaction_name}}:{{react.tally}} </li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends "announcement/base.html" %}
{% block content %}
<h1> Important Announcements </h1>
{% if announce_list %}
<ul>
{% for announce in announce_list %}
<li> <a href = "{% url 'detail' announce.id %}">{{ announce.announcement_title }} by {{announce.author.first_name}} {{announce.author.last_name}} dated {{announce.pub_date|date:"d/m/Y h:i:s A"}} </a></li>
{% endfor %}
</ul>
{% else %}
<p> No announcements here! </p>
{% endif %}
{% endblock %}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'announcement/style.css' %}">
<title>Announcements</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
<p>
<h2>ANNOUNCEMENTS: </h2>
{% for announcement in announcements%}
<p><b>{{announcement.announcement_title}}</b> by {{announcement.author.first_name}} {{announcement.author.last_name}} dated {{announcement.pub_date}}</p>
<p>{{announcement.announcement_body}}</p>
<p>{% include "reactions_list.html" with reactions=announcement.reaction_list %}</p>
{{ value|linebreaks }}
{% endfor %}
</p>
\ No newline at end of file
<p>
<p>{{ reactions.reaction_name }} : {{reactions.tally}}</p>
{% if reactions.reaction_self != NULL %}
<p>{% include "reactions_list.html" with reactions=reactions.reaction_self %}</p>
{% endif %}
</p>
\ No newline at end of file
...@@ -3,5 +3,6 @@ from django.urls import path ...@@ -3,5 +3,6 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.show_announcements, name='show_announcements') path('', views.index, name='index'),
path("<int:announcement_id>", views.detail, name="detail"),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import Http404
from django.shortcuts import render from django.shortcuts import render
from .models import Announcement, Reaction from .models import Announcement, Reaction
# Create your views here. # Create your views here.
def show_announcements(request): #def show_announcements(request):
announcement = Announcement.objects.all() #announcement = Announcement.objects.all()
return render(request, 'announcement_board.html', {'announcements': announcement}) #return render(request, 'announcement/announcement_board.html', {'announcements': announcement})
\ No newline at end of file
def index(request):
announce_list = Announcement.objects.order_by("pub_date")
context = {
"announce_list": announce_list,
}
return render(request, "announcement/announcement_page.html", context)
def detail(request, announcement_id):
try:
announce = Announcement.objects.get(pk=announcement_id)
except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!")
reacts = Reaction.objects.filter(announcement_id=announce).order_by("reaction_name")
return render(request, "announcement/announcement_board.html", {"announce": announce, "reacts": reacts})
\ No newline at end of file
<p> <p>
<i> Reply by {{post.author.first_name}} {{post.author.last_name}} dated {{reply.pub_date}}: </i> <i> Reply by {{post.author.first_name}} {{post.author.last_name}} dated {{reply.pub_date|date:"d/m/Y h:i:s A"}}: </i>
</p> </p>
<p>{{reply.reply_body}}</p> <p>{{reply.reply_body}}</p>
......
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