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.urls import reverse
class Department(models.Model):
dept_name = models.CharField(max_length=255, default='')
home_unit = models.CharField(max_length=255, default='')
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):
first_name = models.CharField(max_length=255, default='')
middle_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):
return 'Name: {}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
\ No newline at end of file
return '{}, {}'.format(self.last_name, self.first_name)
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 .views import index
from .views import (
dashboard_view, WidgetUserDetailView, WidgetUserCreateView, WidgetUserUpdateView
)
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'
\ No newline at end of file
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
def index(request):
return_string = '<p>Welcome to Widget!</p> <p>WIDGET USERS:<br>'
for user in WidgetUser.objects.all():
user_string = '{}, {} {}: {}, {}<br>'.format(
user.last_name, user.first_name, user.middle_name,
user.department.dept_name, user.department.home_unit
)
return_string += user_string
return_string += '</p>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(return_string)
\ No newline at end of file
def dashboard_view(request):
users = WidgetUser.objects.all()
context = {'users' : users}
return render(request, 'dashboard/dashboard.html', context)
class WidgetUserDetailView(DetailView):
model = WidgetUser
template_name = 'dashboard/widgetuser-details.html'
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-add.html'
class WidgetUserUpdateView(UpdateView):
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'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'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