Modified views.py to apply the needed FBV and CBV implementations for the dashboard app's pages.

parent b7630982
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 Department, WidgetUser
from .models import WidgetUser
def index (request):
return_string = '<p>Welcome to Widget!</p> WIDGET USERS:<br>'
for user in WidgetUser.objects.all():
return_string += '{}, {} {}: {}, {}<br>'.format(
user.last_name, user.first_name, user.middle_name, user.department.dept_name, user.department.home_unit
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
def dashboard(request):
users = WidgetUser.objects.all()
return render(request, 'dashboard/dashboard.html', {'users': users})
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'
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