Commit 2004e51e authored by Jenica Vizmanos's avatar Jenica Vizmanos

Edited files to update dashboard and widgetuser details pages and to include...

Edited files to update dashboard and widgetuser details pages and to include add and edit widgetuser pages
parent e03320ff
from django.db import models from django.db import models
from django.urls import reverse
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length=255, default='') dept_name = models.CharField(max_length=255, default='')
home_unit = models.CharField(max_length=255, default='') home_unit = models.CharField(max_length=255, default='')
def __str__(self): def __str__(self):
return 'Department Name and Home Unit: {}, {}'.format(self.dept_name, self.home_unit) return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=255, default='') first_name = models.CharField(max_length=255, default='')
middle_name = models.CharField(max_length=255, default='') middle_name = models.CharField(max_length=255, default='')
last_name = models.CharField(max_length=255, default='') last_name = models.CharField(max_length=255, default='')
department = models.ForeignKey(Department, on_delete=models.CASCADE) department = models.ForeignKey(Department, on_delete=models.CASCADE, verbose_name='Department, Home Unit')
def __str__(self): def __str__(self):
return 'Name: {}, {} {}'.format(self.last_name, self.first_name, self.middle_name) return '{}, {}'.format(self.last_name, self.first_name)
\ No newline at end of file
def get_absolute_url(self):
return reverse('dashboard:widgetuser-details', kwargs={'pk': self.pk})
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import (
dashboard_view, WidgetUserDetailView, WidgetUserCreateView, WidgetUserUpdateView
)
urlpatterns = [ urlpatterns = [
path('', index, name='index') path('', dashboard_view, name='dashboard'),
path('widgetusers/<int:pk>/details/', WidgetUserDetailView.as_view(), name='widgetuser-details'),
path('widgetusers/add/', WidgetUserCreateView.as_view(), name='widgetuser-add'),
path('widgetusers/<int:pk>/edit/', WidgetUserUpdateView.as_view(), name='widgetuser-edit'),
] ]
app_name = 'dashboard' app_name = 'dashboard'
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import WidgetUser from .models import WidgetUser
def index(request): def dashboard_view(request):
return_string = '<p>Welcome to Widget!</p> <p>WIDGET USERS:<br>' users = WidgetUser.objects.all()
context = {'users' : users}
return render(request, 'dashboard/dashboard.html', context)
for user in WidgetUser.objects.all(): class WidgetUserDetailView(DetailView):
user_string = '{}, {} {}: {}, {}<br>'.format( model = WidgetUser
user.last_name, user.first_name, user.middle_name, template_name = 'dashboard/widgetuser-details.html'
user.department.dept_name, user.department.home_unit
)
return_string += user_string
return_string += '</p>' class WidgetUserCreateView(CreateView):
html_string = '<html><body>{}</body></html>'.format(return_string) model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-add.html'
return HttpResponse(return_string) class WidgetUserUpdateView(UpdateView):
\ No newline at end of file model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-edit.html'
\ No newline at end of file
...@@ -64,7 +64,7 @@ ROOT_URLCONF = 'widget_jenicaesports.urls' ...@@ -64,7 +64,7 @@ ROOT_URLCONF = 'widget_jenicaesports.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
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