Commit 98be9750 authored by nheoxoz's avatar nheoxoz

created templates for add, details, and edit

parent 001a00e5
# Generated by Django 4.1.7 on 2023-05-12 04:52
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_remove_announcement_first_name_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='body',
field=models.TextField(default=''),
),
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='announcement',
name='title',
field=models.CharField(default='', max_length=100),
),
]
# Generated by Django 4.1.7 on 2023-05-12 06:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_alter_announcement_body_and_more'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils import timezone
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length=100) title = models.CharField(max_length=100, default="")
body = models.TextField() body = models.TextField(default="")
author = models.ForeignKey( author = models.ForeignKey(
'dashboard.WidgetUser', 'dashboard.WidgetUser',
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='announcements_author' related_name='announcements_author'
) )
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField(default=timezone.now)
def __str__(self): def __str__(self):
return '''{} by {} published {}\n{}'''.format( return '{} by {} {} published {}, {}: {}'.format(
self.title, self.title,
self.author, self.author.first_name,
self.pub_datetime, self.author.last_name,
self.pub_datetime.strftime("%m/%d/%Y"),
self.pub_datetime.strftime("%H:%M %p"),
self.body, self.body,
) )
def format_date(self):
return '{}' .format(self.pub_datetime.strftime("%m/%d/%Y"))
def format_time(self):
return '{}' .format(self.pub_datetime.strftime("%H:%M %p"))
def getLike(self):
try:
return '{}'.format(Reaction.objects.get(name="Like", announcement=self).tally)
except:
return '0'
def getLove(self):
try:
return '{}'.format(Reaction.objects.get(name="Love", announcement=self).tally)
except:
return '0'
def getAngry(self):
try:
return '{}'.format(Reaction.objects.get(name="Angry", announcement=self).tally)
except:
return '0'
def get_absolute_url(self): def get_absolute_url(self):
return reverse( return reverse(
'announcements:announcement-details', 'announcements:announcement-details',
...@@ -43,8 +73,8 @@ class Reaction(models.Model): ...@@ -43,8 +73,8 @@ class Reaction(models.Model):
choices=REACTION_CHOICES, choices=REACTION_CHOICES,
default=REACTION_LIKE, default=REACTION_LIKE,
) )
tally = models.IntegerField() tally = models.IntegerField(default=0)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE) announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return self.name return '{} reactions for {}' .format(self.name, self.announcement)
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Announcement:% {% endblock %}
{% block heading %}<h1>Add a new announcement:</h1>{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<p>
by {{ object.author.first_name }} {{ object.author.last_name }}
</p>
<p>
{{ object.format_date}}, {{ object.format_time }}<br>
{{ object.body }}<br>
Like: {{ object.getLike }}
Love: {{ object.getLove }}
Angry: {{ object.getAngry }}
</p>
<a href="/announcements/{{object.pk}}/edit">
<button class="btn edit">Edit Announcement</button>
</a>
<a href="/announcements/">
<button class="btn edit">Back to Announcement Board</button>
</a>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Announcement{% endblock %}
{% block heading %}Edit announcement:{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
...@@ -9,15 +9,28 @@ ...@@ -9,15 +9,28 @@
<p> <p>
Announcements:<br> Announcements:<br>
{% for a in announcements %} {% for a in announcements %}
<a href="{{ user.get_absolute_url }}"> <a href="{{ a.get_absolute_url }}">
{{a.title}} by {{ a.author }} {{a.title}} by {{ a.author.first_name }} {{ a.author.last_name }}
</a><br> </a><br>
{% endfor %} {% endfor %}
</p> </p>
{% endblock %} {% endblock %}
{% block footing %} {% block footing %}
<a href="{% url 'announcements:announcement-create' %}"> <a href="/announcements/add">
<button class="btn add">Add Announcement</button> <button class="btn add">Add Announcement</button>
</a> </a>
<button type="button" class="btn">
<a href="/dashboard/" class="link-light">Dashboard</a>
</button> &nbsp;
<button type="button" class="btn">
<a href="/forum/" class="link-light">Forum</a>
</button> &nbsp;
<button type="button" class="btn">
<a href="/assignments/" class="link-light">Assignments</a>
</button> &nbsp;
<button type="button" class="btn">
<a href="/widget_calendar/" class="link-light">Calendar</a>
</button>
{% endblock %} {% endblock %}
...@@ -9,15 +9,15 @@ from .views import ( ...@@ -9,15 +9,15 @@ from .views import (
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('announcements/<int:pk>/details/', path('<int:pk>/details/',
AnnouncementsDetailView.as_view(), AnnouncementsDetailView.as_view(),
name='announcement-details'), name='announcement-details'),
path('announcements/add/', path('add/',
AnnouncementsCreateView.as_view(), AnnouncementsCreateView.as_view(),
name='announcement-create'), name='announcement-add'),
path('announcements/<int:pk>/edit/', path('<int:pk>/edit/',
AnnouncementsUpdateView.as_view(), AnnouncementsUpdateView.as_view(),
name='announcement-update'), name='announcement-edit'),
] ]
......
...@@ -20,11 +20,11 @@ class AnnouncementsDetailView(DetailView): ...@@ -20,11 +20,11 @@ class AnnouncementsDetailView(DetailView):
class AnnouncementsCreateView(CreateView): class AnnouncementsCreateView(CreateView):
model = Announcement model = Announcement
fields = '__all__' fields = 'title', 'body', 'author'
template_name = 'announcements/announcement-add.html' template_name = 'announcements/announcement-add.html'
class AnnouncementsUpdateView(UpdateView): class AnnouncementsUpdateView(UpdateView):
model = Announcement model = Announcement
fields = '__all__' fields = 'title', 'body', 'author'
template_name = 'announcements/announcement-edit.html' template_name = 'announcements/announcement-edit.html'
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