Commit b49eea13 authored by Brendan Fausto's avatar Brendan Fausto

Merge branch 'dashboard_app' into 'master'

Dashboard app

See merge request !2
parents bcd840b1 76cad784
from django.contrib import admin
from .models import Department, WidgetUser
class DepartmentAdmin(admin.ModelAdmin):
model = Department
search_fields = ('dept_name','home_unit',)
list_display = ('dept_name','home_unit',)
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
search_fields = ('first_name','middle_name','last_name','department',)
list_display = ('first_name','middle_name','last_name','department',)
list_filter = ('department',)
admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, WidgetUserAdmin)
\ No newline at end of file
from django.apps import AppConfig
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
# Generated by Django 4.1.6 on 2023-03-05 03:39
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=255)),
('home_unit', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=255)),
('middle_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='dashboard.department')),
],
),
]
from django.db import models
class Department(models.Model):
dept_name = models.CharField(max_length=255)
home_unit = models.CharField(max_length=255)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=255)
middle_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
department = models.ForeignKey('Department', on_delete=models.PROTECT)
@property
def dept_name(self):
return self.department.dept_name
@property
def home_unit(self):
return self.department.home_unit
def __str__(self):
return '{}, {} {}: {}, {}'.format(self.last_name, self.first_name, self.middle_name, self.dept_name, self.home_unit)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
# dashboard/urls.py
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "dashboard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser
# Create your views here.
def index(request):
return_string = '<body>Welcome to Widget!<br><br>WIDGET USERS:<br><ul>'
for user in WidgetUser.objects.all():
user_string = '<li>{}</li>'.format(user.__str__())
return_string += user_string
return_string += '</ul></body>'
html_string = '<html>{}</html>'.format(return_string)
return HttpResponse(html_string)
......@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dashboard',
]
MIDDLEWARE = [
......
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
]
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