Commit 090c9a66 authored by Ian Rafael T. Aragoza's avatar Ian Rafael T. Aragoza

Merge branch 'announcementboard_feature' into 'master'

Announcementboard merge into master

See merge request !1
parents bcd184ee 0a8a3ad8
from django.contrib import admin 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. # Register your models here.
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
# Generated by Django 4.1.7 on 2023-03-04 14:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('tally', models.IntegerField()),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcementboard.announcement')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 16:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcementboard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='announcements', to='dashboard.widgetuser'),
),
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(verbose_name='Posted On'),
),
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reacts', to='announcementboard.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=255),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
# Generated by Django 4.1.7 on 2023-03-04 17:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcementboard', '0002_alter_announcement_author_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_datetime',
field=models.DateTimeField(auto_now_add=True, verbose_name='Posted On'),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(blank=True, default=0, null=True),
),
]
from django.db import models from django.db import models
from django.urls import reverse
from dashboard.models import WidgetUser
# Create your models here. # 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, related_name="announcements")
pub_datetime = models.DateTimeField(verbose_name="Posted On", auto_now_add=True)
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('announcement_detail', args=[str(self.title)])
class Reaction(models.Model):
reaction_names = [('Like','Like'),('Love','Love'),('Angry','Angry')]
name = models.CharField(choices=reaction_names, max_length=255)
tally = models.IntegerField(default=0, blank=True, null=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name="reacts")
def __str__(self):
return '{}'.format(self.name)
def get_absolute_url(self):
return reverse('reaction_detail', args=[str(self.name)])
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse('Announcement Board app.') output = "<h1><b> Widget's Announcement Board </b></h1> <br> <h3>Announcements:</h3>"
for announcement in Announcement.objects.order_by('-pub_datetime'):
output += '{} by {} {} published {}:<br> {} <br>'.format(
announcement.title, announcement.author.first_name, announcement.author.last_name, announcement.pub_datetime.strftime("%m/%d/%Y %I:%M %p"), announcement.body)
reactList = announcement.reacts.all()
for react in reactList:
output += '{}: {} <br>'.format(react.name, react.tally)
output += '<br>'
return HttpResponse(output)
from django.contrib import admin from django.contrib import admin
from .models import Department, WidgetUser
# Register your models here. class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name', 'home_unit',)
search_fields = ('dept_name',)
list_filter = ('home_unit',)
class UserAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = ('last_name', 'first_name', 'middle_name', 'department',)
search_fields = ('last_name', 'first_name', 'middle_name',)
list_filter = ('department',)
fieldsets = [
('Name', {
'fields': [
# the tuple puts these fields in a single line
('last_name', 'first_name', 'middle_name'), 'department'
]
}),
]
admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, UserAdmin)
\ No newline at end of file
# Generated by Django 4.1.7 on 2023-03-04 11:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=48, unique=True)),
('home_unit', models.CharField(max_length=48)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.TextField(max_length=48)),
('middle_name', models.TextField(max_length=48)),
('last_name', models.TextField(max_length=48)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='department', to='dashboard.department')),
],
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
from django.db import models
from django.urls import reverse
class Department(models.Model):
dept_name = models.CharField(max_length=48, unique=True)
home_unit = models.CharField(max_length=48)
def __str__(self):
return '{}'.format(self.dept_name)
def get_absolute_url(self):
return reverse('department_detail', args=[str(self.dept_name)])
class WidgetUser(models.Model):
first_name = models.TextField(max_length=48)
middle_name = models.TextField(max_length=48)
last_name = models.TextField(max_length=48)
department = models.ForeignKey(Department, on_delete=models.CASCADE, related_name='department')
def __str__(self):
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
def get_absolute_url(self):
return reverse('user_detail', args=[str(self.last_name)])
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse('Dashboard app.') output = "Welcome to Widget!<br><br> WIDGET USERS:<br>"
userList = WidgetUser.objects.order_by('last_name')
output += '<br>'.join(['{}, {} {}: {}, {}'.format(user.last_name, user.first_name, user.middle_name, user.department, user.department.home_unit) for user in userList])
return HttpResponse(output)
...@@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/ ...@@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
from pathlib import Path from pathlib import Path
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os
load_dotenv() load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
...@@ -106,6 +107,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -106,6 +107,7 @@ AUTH_PASSWORD_VALIDATORS = [
] ]
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
...@@ -117,7 +119,6 @@ USE_I18N = True ...@@ -117,7 +119,6 @@ USE_I18N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/ # https://docs.djangoproject.com/en/4.1/howto/static-files/
......
...@@ -17,8 +17,8 @@ from django.contrib import admin ...@@ -17,8 +17,8 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('dashboard', include('dashboard.urls', namespace="dashboard")), path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('announcementboard', include('announcementboard.urls', namespace="announcementboard")), path('announcementboard/', include('announcementboard.urls', namespace="announcementboard")),
path('forum', include('forum.urls', namespace="forum")), path('forum/', include('forum.urls', namespace="forum")),
path('admin/', admin.site.urls), 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