Commit fc46209f authored by Teo Quinto's avatar Teo Quinto

changed index from FBV to CBV

parent 8781eaa5
...@@ -5,15 +5,13 @@ ...@@ -5,15 +5,13 @@
{% block content %} {% block content %}
<h1>Welcome to Widget!</h1> <h1>Welcome to Widget!</h1>
<p>Widget Users:</p> <p>Widget Users:</p>
{% if users %} <ol>
<ol> {% for object in object_list %}
{% for user in users %} <li><a href="users/{{ object.id }}/details/">{{ object.last_name }},
<li><a href="users/{{ user.id }}/details/">{{ user.last_name }}, {{ object.first_name }} {{ object.middle_name }}</a></li>
{{ user.first_name }} {{ user.middle_name }}</a></li> {% empty %}
{% endfor %} <li>No users registered.</li>
</ol> {% endfor %}
{% else %} </ol>
<p>No users are available</p>
{% endif %}
<button onclick="window.location.href='users/add/';">Add Widget User</button> <button onclick="window.location.href='users/add/';">Add Widget User</button>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -3,7 +3,7 @@ from django.urls import path ...@@ -3,7 +3,7 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.IndexView.as_view(), name='index'),
# homepage/users/1/details/ # homepage/users/1/details/
path("users/<int:user_id>/details/", views.details, name="details"), path("users/<int:user_id>/details/", views.details, name="details"),
# homepage/users/add/ # homepage/users/add/
......
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.views.generic.list import ListView
from .models import Department, WidgetUser from .models import Department, WidgetUser
from .forms import WidgetUserForm from .forms import WidgetUserForm
# Create your views here. # Create your views here.
def index(request): class IndexView(ListView):
users = WidgetUser.objects.order_by("last_name") queryset = WidgetUser.objects.order_by("last_name")
context = {
"users": users,
}
return render(request, "homepage/index.html", context)
def details(request, user_id): def details(request, user_id):
try: try:
......
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