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