adding a completed announcementsv2

parent a6960e20
# Generated by Django 4.2.1 on 2023-05-14 10:14
import datetime
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 14, 7, 675506, tzinfo=datetime.timezone.utc), null=True),
),
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reactions', to='announcements.announcement'),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:15
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0002_alter_announcement_pub_datetime_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 15, 20, 437714), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:16
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 16, 2, 52254, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:19
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 19, 54, 26317), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:19
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 19, 58, 681479), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:20
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0006_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 20, 10, 470392), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:20
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 20, 54, 417267, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:21
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0008_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 21, 58, 841410, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:23
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0009_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 23, 45, 514623, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:26
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0010_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(null=True, verbose_name=datetime.datetime(2023, 5, 14, 10, 26, 29, 923612, tzinfo=datetime.timezone.utc)),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:27
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0011_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=datetime.datetime(2023, 5, 14, 10, 27, 0, 13958, tzinfo=datetime.timezone.utc), null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0012_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default='django.utils.timezone.now', null=True),
),
]
# Generated by Django 4.2.1 on 2023-05-14 10:37
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('announcements', '0013_alter_announcement_pub_datetime'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(default=django.utils.timezone.now, null=True),
),
]
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
import django
class Announcement(models.Model):
title = models.CharField(max_length=255, null=True)
body = models.TextField(null=True)
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(null=True)
pub_datetime = models.DateTimeField(default = django.utils.timezone.now, null=True)
def __str__(self):
return f"{self.title}"
......@@ -14,7 +16,7 @@ class Announcement(models.Model):
class Reaction(models.Model):
name = models.CharField(max_length=255, null=True)
tally = models.IntegerField(null=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True, related_name='reactions')
def __str__(self):
return f"{self.name}"
\ No newline at end of file
<form method="POST" enctype="multipart/form-data">
<!-- Security token -->
{% csrf_token %}
<!-- Using the formset -->
{{ form.as_p }}
<input type="submit" value="Save New Announcement">
</form>
{% extends 'base.html' %}
{% block title %} {{myannouncement.title}} {% endblock %}
{% block content %}
<h1>{{ myannouncement.title }}</h1>
<p><b> by {{ myannouncement.author.first_name }} {{ myannouncement.author.last_name }}</b></p>
<p><b>{{ myannouncement.pub_datetime | date:"m/d/Y, h:i A" }}</p>
<p><b>{{ myannouncement.body }}</p>
<ul>
{% for x in reactions %}
<li>{{ x.name }} {{ x.tally }}</li>
{% endfor %}
</ul>
<form action='edit' method="get" enctype="multipart/form-data">
{% csrf_token %}
<input type="submit" value="Edit Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Announcement{% endblock %}
{% block content %}
<form method="post" enctype="multipart/form-data">
<!-- Security token -->
{% csrf_token %}
<!-- Using the formset -->
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Announcements{% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcements!</h1>
{%for object in announcements%}
<a href="{{ object.pk }}/details">{{ object.title }} by {{ object.author.first_name }} {{ object.author.last_name }}</a>
<br>
{%endfor%}
<form action="/announcements/add" method="get" enctype="multipart/form-data">
{% csrf_token %}
<input type="submit" value="New Announcement">
</form>
<br>
<a href="/dashboard">Dashboard</a>
<br>
<a href="/assignments">Assignments</a>
<br>
<a href="/forum">Forum</a>
<br>
<a href="/calendar">Calendar</a>
<br>
{% endblock %}
from django.urls import path
from .views import index
from .views import announcements_view, AnnouncementsDetailView, AnnouncementsCreateView, AnnouncementsUpdateView
urlpatterns = [
path('', index, name='index'),
path('', announcements_view, name='announcements_page'),
path('<int:pk>/details/', AnnouncementsDetailView.as_view(), name='announcements-details'),
path('add', AnnouncementsCreateView.as_view(), name='announcements-add'),
path('<int:pk>/details/edit', AnnouncementsUpdateView.as_view(), name='announcements-edit'),
]
app_name = "announcements"
\ No newline at end of file
......@@ -2,6 +2,9 @@ from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
import datetime
from django.views.generic import CreateView, UpdateView
from django.views.generic.detail import DetailView
from django.urls import reverse
def index(request):
overall_board = "<html><title>Announcement Board</title><body>" \
......@@ -20,4 +23,41 @@ def index(request):
overall_board += "%i<br>" %reaction.tally
overall_board += "</body></html>"
return HttpResponse(overall_board)
\ No newline at end of file
return HttpResponse(overall_board)
def announcements_view(request):
announcements = Announcement.objects.all().order_by('-pub_datetime')
return render(request, 'announcements/announcements.html', {'announcements': announcements})
class AnnouncementsDetailView(DetailView):
def get(self, request, pk):
myannouncement = Announcement.objects.get(pk=pk)
reactions = myannouncement.reactions.all().values()
context = {
'myannouncement': myannouncement,
'reactions': reactions,
}
return render(request, 'announcements/announcement-details.html', context)
class AnnouncementsCreateView(CreateView):
model = Announcement
fields = ["title", "body", "author"]
template_name = 'announcements/announcement-add.html'
def get_success_url(self):
return reverse('announcements:announcements-details', kwargs={'pk': self.object.pk})
class AnnouncementsUpdateView(UpdateView):
model = Announcement
fields = ["title", "body", "author"]
template_name = 'announcements/announcement-edit.html'
def get_success_url(self):
return reverse('announcements:announcements-details', kwargs={'pk': self.object.pk})
No preview for this file type
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -59,7 +60,7 @@ ROOT_URLCONF = 'widget_group3.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
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