Commit fc46209f authored by Teo Quinto's avatar Teo Quinto

changed index from FBV to CBV

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