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