Commit 86d2ff98 authored by Alec Dayupay's avatar Alec Dayupay

Edited announcements

parent 1b22d175
from django.forms import ModelForm
from .models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = '__all__'
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length = 50) title = models.CharField(max_length = 50)
...@@ -9,6 +10,9 @@ class Announcement(models.Model): ...@@ -9,6 +10,9 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
def get_absolute_url(self):
return reverse("announcement-details", kwargs={'pk': self.pk})
class Reaction(models.Model): class Reaction(models.Model):
Like = 'Like' Like = 'Like'
Love = 'Love' Love = 'Love'
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Annoucement{% endblock %}
{% block content %}
<p>Add a new announcement:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save New Announcement">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block heading %}{{ object.title }}{% endblock %}
{% block content %}
<p>by {{ object.author }}</p>
<p>{{ object.datetime }}</p>
<p>{{ object.body }}</p>
<p><br>Reactions:</p>
{% for reac in object.reaction_set.all %}
<p>by {{ reac.name }}: {{ reac.tally }}</p>
{% endfor %}
<input type="button" value="Edit Post" onclick="location.href='{% url 'forumpost-edit' object.pk %}'"/>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Announcement{% endblock %}
{% block content %}
<p>Edit Announcement:</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes to Announcement">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block heading %}Welcome to Widget's Forum!{% endblock %}
{% block content %}
<p>Announcements:</p>
{% for ann in announcements %}
<p><a href="{% url 'announcement-details' ann.pk %}">{{ ann.title }} by {{ ann.author }}</a></p>
{% endfor %}
<input type="button" value="New Post" onclick="location.href='{% url 'announcement-add' %}'"/>
{% endblock %}
{% block links %}
<p><a href="http://localhost:8000/dashboard/">Dashboard</a></p>
<p><a href="http://localhost:8000/announcements/">Announcement</a></p>
<p><a href="http://localhost:8000/assignments/">Assignment</a></p>
<p><a href="http://localhost:8000/calendar/">Calendar</a></p>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from . import views
from .views import (AnnouncementDetailView, AnnouncementCreateView, AnnouncementUpdateView)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', views.announcements, name="announcements"),
path('announcements/<int:pk>/details/', AnnouncementDetailView.as_view(), name="announcement-details"),
path('announcements/add/', AnnouncementCreateView.as_view(), name="announcement-add"),
path('announcements/<int:pk>/edit/', AnnouncementUpdateView.as_view(), name="announcement-edit"),
] ]
\ No newline at end of file
app_name = "announcements"
from django.http import HttpResponse from django.shortcuts import render
from .models import Announcement, Reaction from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement
def index(request): def announcements(request):
announcements = Announcement.objects.all() return render(request, 'announcements/announcements.html', {'announcements': Announcement.objects.order_by('-pub_datetime')})
reactions = Reaction.objects.all()
response = "Widget's Announcement Board<br><br>Announcements:<br>" class AnnouncementDetailView(DetailView):
for announcement in announcements: model = Announcement
response += "{} by {} published {}:<br>{}<br>".format( template_name = 'announcements/announcement-details.html'
announcement.title,
announcement.author,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
announcement.body
)
for reaction in reactions: class AnnouncementCreateView(CreateView):
if reaction.announcement == announcement: model = Announcement
response += "{}: {}<br>".format( fields = '__all__'
reaction.name, template_name = 'announcements/announcement-add.html'
str(reaction.tally)
)
response += "<br>"
return HttpResponse(response)
class AnnouncementUpdateView(UpdateView):
model = Announcement
fields = '__all__'
template_name = 'announcements/announcement-edit.html'
\ No newline at end of file
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