Commit 3c34dc93 authored by John Tamano's avatar John Tamano

Added views to display model data under homepage

parent 24b13a16
...@@ -20,6 +20,6 @@ class WidgetUser(models.Model): ...@@ -20,6 +20,6 @@ class WidgetUser(models.Model):
) )
def __str__(self): def __str__(self):
return'{}'.format(self.first_name) return'{}'.format(self.last_name, self.first_name + self.middle_name, self.id_num, self.email)
# Create your models here. # Create your models here.
\ No newline at end of file
{% block content %}
<h1>WIDGET USERS:</h1>
{% for WidgetUser in displayWidgetUsers %}
<p>
{{WidgetUser.last_name}}, {{WidgetUser.first_name}} {{WidgetUser.middle_name}}:
{{WidgetUser.id_num}}, {{WidgetUser.email}}, {{WidgetUser.department}}, {{WidgetUser.department.home_unit}}
</p>
{% endfor %}
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import displayWidgetUsers, index
urlpatterns = [ urlpatterns = [
path('',index, name='index') path('',displayWidgetUsers, name='displayWidgetUsers')
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.template.loader import get_template
from homepage.models import Department, WidgetUser
from django.template import Template, Context
from django.http import HttpResponse from django.http import HttpResponse
from . import models
def index(request): def index(request):
return HttpResponse('Welcome to Widget!') return HttpResponse('Welcome to Widget!')
def displayWidgetUsers(request):
WidgetUsers = models.WidgetUser.objects.all()
WidgetUserTemplate = get_template('homepage.html')
display = WidgetUserTemplate.render({'displayWidgetUsers': WidgetUsers})
return HttpResponse(display)
# Create your views here. # Create your views here.
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