Commit e0efef88 authored by Almira Redoble's avatar Almira Redoble

Merge branch 'dashboard' into 'main'

Dashboard

See merge request !1
parents 4afd57fc 34dd94ea
from django.contrib import admin
from .models import Department, WidgetUser
class WidgetUserInline(admin.TabularInline):
model = WidgetUser
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = ('last_name', 'first_name', 'department')
search_fields = ('last_name', 'first_name', 'department')
list_filter = ('last_name', 'department')
fieldsets = [
('Name', {
'fields':
(('last_name', 'first_name'), 'middle_name', 'department',),
}),
]
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name', 'home_unit')
search_fields = ('dept_name', 'home_unit')
list_filter = ('home_unit', )
fieldsets = [
('Details', {
'fields':
(('dept_name', 'home_unit'),),
}),
]
inlines = [WidgetUserInline, ]
admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, WidgetUserAdmin)
from django.apps import AppConfig
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
# Generated by Django 3.2 on 2023-03-01 01:38
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(default='', max_length=100)),
('home_unit', models.CharField(default='', max_length=100)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(default='', max_length=50)),
('middle_name', models.CharField(default='', max_length=50)),
('last_name', models.CharField(default='', max_length=50)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='User', to='dashboard.department')),
],
),
]
from django.db import models
class Department(models.Model):
dept_name = models.CharField(max_length=100, default="")
home_unit = models.CharField(max_length=100, default="")
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=50, default="")
middle_name = models.CharField(max_length=50, default="")
last_name = models.CharField(max_length=50, default="")
department = models.ForeignKey(
Department,
on_delete=models.CASCADE,
related_name='User'
)
def __str__(self):
return '{}, {} {}'.format(
self.last_name,
self.first_name,
self.middle_name
)
from django.test import TestCase
# Create your tests here.
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
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:500%;'>\
Welcome to Widget!\
</h1>"
body = "<h2>WIDGET USERS:</h2>"
for user in WidgetUser.objects.all():
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
{}: {}<br>\
</p>".format(user, user.department)
return_string = "<html>\
<body style = 'font-family:helvetica;\
padding:30px;'>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
...@@ -40,6 +40,7 @@ INSTALLED_APPS = [ ...@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dashboard',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), 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