Adding the dashboard app

parent ba2e2cf6
from django.contrib import admin
# Register your models here.
from .models import department, widgetUser
class departmentAdmin(admin.ModelAdmin):
model = department
search_fields = ('dept_name', 'home_unit')
list_display = ('dept_name', 'home_unit')
list_filter = ('dept_name', 'home_unit')
class widgetUsersAdmin(admin.ModelAdmin):
model = widgetUser
search_fields = ('first_name', 'middle_name', 'last_name', 'department')
list_display = ('first_name', 'last_name', 'department')
list_filter = ('first_name', 'last_name', 'department')
admin.site.register(department, departmentAdmin)
admin.site.register(widgetUser, widgetUsersAdmin)
\ No newline at end of file
......@@ -3,4 +3,4 @@ from django.apps import AppConfig
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
name = 'dashboard'
\ No newline at end of file
# Generated by Django 3.2 on 2023-03-02 07:28
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=100)),
('home_unit', models.CharField(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(max_length=100)),
('middle_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.department')),
],
),
]
from django.db import models
from django.urls import reverse
# Create your models here.
class department(models.Model):
dept_name = models.CharField(max_length = 100)
home_unit = models.CharField(max_length = 100, )
def __str__(self):
return '{}'.format(self.dept_name)
def get_absolute_url(self):
return reverse('department', args= [str(self.dept_name)])
class widgetUser(models.Model):
first_name = models.CharField(max_length = 100)
middle_name = models.CharField(max_length = 100)
last_name = models.CharField(max_length = 100)
department = models.ForeignKey(
department,
on_delete = models.CASCADE,)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('widgetUser', args= [str(self.last_name)])
\ No newline at end of file
from django.urls import path
from .views import dashboard
urlpatterns = [
path('', dashboard, name = "dashboard")
]
app_name = "dashboard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import department, widgetUser
# Create your views here.
def dashboard(request):
welcome_message = "Welcome to Widget!<br><br>WIDGET USERS:<br>"
all_widgetUser = widgetUser.objects.all()
for member in all_widgetUser:
last_name = member.last_name
first_name = member.first_name
middle_name = member.middle_name
dept_name = member.department.dept_name
home_unit = member.department.home_unit
output = "{lastName}, {firstName} {middleName}: {deptName}, {homeUnit}<br>".format(lastName = last_name, firstName = first_name, middleName = middle_name, deptName = dept_name, homeUnit = home_unit)
welcome_message += output
return HttpResponse(welcome_message)
\ No newline at end of file
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