Commit ad570874 authored by Ross Batacan's avatar Ross Batacan

Created announcements/add URL with created template announcements-add.html

parent 3b893033
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
# Create your models here.
# please insert foreign key from dashboard application on announcement_author
class Announcement(models.Model):
announcement_title = models.CharField(max_length=50, unique=True, null=True, )
announcement_body = models.CharField(max_length=250, unique=True, null=True, )
announcement_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True)
announcement_title = models.CharField(max_length=50, unique=True, null=True, verbose_name="Title" )
announcement_body = models.TextField(max_length=250, unique=True, null=True, verbose_name="Body")
announcement_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True, verbose_name="Author")
announcement_pub_datetime = models.DateTimeField(null=True, )
def __str__(self):
return self.announcement_title
def get_absolute_url(self):
return reverse('announcements:announcement-details', kwargs={'pk': self.pk})
reaction_choices = (
('Like', 'Like'),
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} Add Announcement {% endblock %}
{% block content %}
<h1> Add a new announcement</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Add Announcement">
</form>
{% endblock %}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<h1>Welcome to Widget's Announcement Board!</h1>
<h3>Announcements:</h3>
{% for announcement in announcements %}
<a href="{{ announcement.get_absolute_url }}"> {{ announcement.announcement_title }}
<a href="{ % url 'announcements:announcement-details' announcement.id % }"> {{ announcement.announcement_title }}
by {{ announcement.announcement_author.first_name }} {{ announcement.announcement_author.last_name }}
</a> <br>
{% endfor %} <br>
......
......@@ -22,6 +22,8 @@ class AnnouncementsDetailsView(DetailView):
class AnnouncementsCreateView(CreateView):
model = Announcement
fields = 'announcement_title', 'announcement_body', 'announcement_author'
template_name = 'announcements/announcement-add.html'
class AnnouncementsEditView(UpdateView):
......
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