Commit 2565072e authored by Joshua Son's avatar Joshua Son

Improvement: New and improved announcement page with images and style

parent 3d2d6be6
# 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 { h1 {
color: purple; color: purple;
font-weight:bold; font-weight:bold;
font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
} }
p { p {
color: orange; color: orange;
font-weight:bold; font-weight:bold;
font-family:'Courier New', Courier, monospace;
} }
body { body {
background-color: beige; background-color: beige;
font-family:'Courier New', Courier, monospace;
} }
a { a {
color: orangered; color: orangered;
......
{% extends "announcement/base.html" %} {% extends "announcement/base.html" %}
{% block content %} {% block content %}
<img src="{{announce.announce_image.url}}">
<h1> {{ announce.announcement_title }} </h1> <h1> {{ announce.announcement_title }} </h1>
<p> <em> by {{ announce.author.first_name}} {{announce.author.last_name}}, {{announce.pub_date}} </em> </p> <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> <p> {{announce.announcement_body}}</p>
<ul>
{% for react in reacts %}
<p> {% include "announcement/reactions_list.html" with reactions=announce.reaction_list %}</p> <li> {{react.reaction_name}}:{{react.tally}} </li>
{% endfor %}
</ul>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% if announce_list %} {% if announce_list %}
<ul> <ul>
{% for announce in announce_list %} {% 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}} </a></li> <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 %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
......
{% extends "announcement/base.html" %}
<p>
<p>{{ reactions.reaction_name }} : {{reactions.tally}}</p>
{% if reactions.reaction_self != NULL %}
<p>{% include "announcement/reactions_list.html" with reactions=reactions.reaction_self %}</p>
{% endif %}
</p>
\ No newline at end of file
from django.http import Http404 from django.http import Http404
from django.shortcuts import render from django.shortcuts import render
from .models import Announcement from .models import Announcement, Reaction
# Create your views here. # Create your views here.
...@@ -22,4 +22,5 @@ def detail(request, announcement_id): ...@@ -22,4 +22,5 @@ def detail(request, announcement_id):
except Announcement.DoesNotExist: except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!") raise Http404("Announcement does not exist!")
return render(request, "announcement/announcement_board.html", {"announce": announce}) reacts = Reaction.objects.filter(announcement_id=announce).order_by("reaction_name")
\ No newline at end of file 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