Commit b35c0529 authored by Lay Villanueva's avatar Lay Villanueva

Updated models.py, admin.py and started views.py

Created Announcement and Reaction classes in models.py and fixed an error in urls.py of the main project
parent bbdd760c
Pipeline #2933 failed with stages
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
search_fields = ('title','author')
list_display = ('title', 'author', 'pub_datetime', 'body')
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
search_fields = ('name', 'announcement')
list_display = ('announcement', 'name', 'tally')
# Register your models here.
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
from django.db import models
from django.urls import reverse
from dashboard.models import WidgetUser
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length=255)
body = models.TextField()
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('announcement_detail', args=[str(self.title)])
class Reaction(models.Model):
name = models.CharField(max_length=255)
tally = models.IntegerField()
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return '{}'.format(self.name)
def get_absolute_url(self):
return reverse('reaction_detail', args=[str(self.name)])
......@@ -4,4 +4,4 @@ from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('Announcement Board app.')
return HttpResponse("Widget's Announcement Board <br> Announcements: <br>")
......@@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
from pathlib import Path
from dotenv import load_dotenv
import os
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
......
......@@ -17,8 +17,8 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('dashboard', include('dashboard.urls', namespace="dashboard")),
path('announcementboard', include('announcementboard.urls', namespace="announcementboard")),
path('forum', include('forum.urls', namespace="forum")),
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('announcementboard/', include('announcementboard.urls', namespace="announcementboard")),
path('forum/', include('forum.urls', namespace="forum")),
path('admin/', admin.site.urls),
]
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