changed announcement page, added individual announcement pages, added css

parent f00356ce
# Generated by Django 3.2.12 on 2022-05-24 08:34
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Forum', '0004_reply_reply_post'),
]
operations = [
migrations.RemoveField(
model_name='post',
name='post_imageUrl',
),
]
# Generated by Django 3.2.12 on 2022-05-24 08:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Forum', '0005_remove_post_post_imageurl'),
]
operations = [
migrations.AddField(
model_name='post',
name='post_imageUrl',
field=models.CharField(default=1, max_length=999),
),
]
# Generated by Django 3.2.12 on 2022-05-24 08:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_announcement_author_and_more'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='announcement_imageUrl',
field=models.CharField(default='', max_length=999),
),
]
# Generated by Django 3.2.12 on 2022-05-24 08:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_announcement_announcement_imageurl'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='announcement_imageUrl',
field=models.CharField(default=1, max_length=999),
),
]
# Generated by Django 3.2.12 on 2022-05-24 08:36
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_alter_announcement_announcement_imageurl'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='announcement_imageUrl',
),
]
# Generated by Django 3.2.12 on 2022-05-24 08:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_remove_announcement_announcement_imageurl'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='announcement_imageUrl',
field=models.CharField(default=1, max_length=999),
),
]
...@@ -7,6 +7,7 @@ class Announcement(models.Model): ...@@ -7,6 +7,7 @@ class Announcement(models.Model):
announcement_body = models.CharField(max_length=400) announcement_body = models.CharField(max_length=400)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
announcement_imageUrl = models.CharField(max_length=999, default = 1)
def __str__(self): def __str__(self):
return self.announcement_title return self.announcement_title
......
h1 {
font-family: 'Courier New', Courier, monospace;
}
h3 {
font-family: 'Courier New', Courier, monospace;
border: 2px solid black;
background-color: azure;
}
body {
background-color: bisque;
}
ul {
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
list-style-type: square;
border: 5px solid black;
background-color: aliceblue;
}
img {
max-width: 500px;
}
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<h1>{{announcement.announcement_title}}</h1>
<h4>{{announcement.author.first_name}} {{announcement.author.last_name}}, {{announcement.pub_date.day}}/{{announcement.pub_date.month}}/{{announcement.pub_date.year}}</h4>
<img src= {{announcement.announcement_imageUrl}}>
<h3>{{announcement.announcement_body}}</h3>
<ul>
{% for reaction in announcement.reaction_set.all %}
<li>{{reaction.reaction_name|lower|capfirst }}: {{reaction.tally}}</li><br>
{% endfor %}
</ul>
{% 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 'announcements/style.css' %}">
<title></title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<h1>Announcement Board</h1>
{% if announcement_list %}
<ul>
{% for announcement in announcement_list %}
<h3><li><a href ="{% url 'announcement' announcement.id %}">{{announcement.announcement_title}}</a>
</br> by {{announcement.author.first_name}} {{announcement.author.last_name}} dated {{announcement.pub_date.day}}/{{announcement.pub_date.month}}/{{announcement.pub_date.year}}</li></h3>
{% endfor %}
</ul>
{% else %}
<p>No announcements available.</p>
{% endif %}
{% endblock %}
\ No newline at end of file
...@@ -3,6 +3,6 @@ from django.urls import path ...@@ -3,6 +3,6 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index') path('', views.index, name='index'),
path("<int:announcement_id>/details/", views.announcement, name='announcement')
] ]
...@@ -6,18 +6,19 @@ from django.shortcuts import render ...@@ -6,18 +6,19 @@ from django.shortcuts import render
# Create your views here. # Create your views here.
def index(request): def index(request):
announcement_objects = Announcement.objects.all() announcement = Announcement.objects.all()
response = "<h1>~~~Announcements~~~</h1> <br><br>" reaction = Reaction.objects.all()
announcement_list = Announcement.objects.order_by("pub_date")
context ={
'announcement':announcement,
'reaction':reaction,
'announcement_list':announcement_list
}
return render(request, "announcements/view.html", context)
for announcement in announcement_objects: def announcement(request, announcement_id):
try:
like = announcement.reaction_set.get(reaction_name="LIKE").tally announcement = Announcement.objects.get(pk=announcement_id)
love = announcement.reaction_set.get(reaction_name="LOVE").tally except Announcement.DoesNotExist:
angry = announcement.reaction_set.get(reaction_name="ANGRY").tally raise Http404("Announcement doesnt exist")
return render(request, "announcements/announcement.html", {"announcement": announcement})
response = (response + f"{announcement.announcement_title} by " \ No newline at end of file
+ f"{announcement.author.first_name} {announcement.author.last_name}<br>"
+ f"dated {announcement.pub_date}: <br><br> {announcement.announcement_body}<br><br>"
+ f"Like: {like} <br> Love: {love} <br> Angry: {angry} <br><br><br>")
return HttpResponse(response)
\ No newline at end of file
No preview for this file type
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