Commit 63572b8e authored by justin's avatar justin

feat: added DetailViews per user

parent bc58a526
from django.db import models
from django.urls import reverse
class Department(models.Model):
......@@ -23,3 +24,9 @@ class WidgetUser(models.Model):
def displayName(self):
return f"{self.first_name} {self.last_name}"
def get_absolute_url(self):
return reverse(
"dashboard:user-detail",
kwargs={"pk": self.pk},
)
......@@ -4,7 +4,7 @@
<h2>Widget Users:</h2>
<ul>
{% for user in users %}
<a href="">
<a href="{{user.get_absolute_url}}">
<li>{{ user.last_name }}, {{ user.first_name }}</li>
</a>
{% endfor %}
......
{% extends 'base.html' %}
{% block content %}
<div class="user-name">
<h1>{{ object.first_name }}
{{ object.middle_name }}
{{ object.last_name }}
</h1>
<h2>{{ object.department.dept_name }}</h2>
<h2>{{ object.department.home_unit }}</h2>
</div>
<a href="./edit">Edit Widget User</a>
{% endblock %}
......@@ -4,6 +4,16 @@ from . import views
urlpatterns = [
path("", views.dashboard, name="dashboard"),
path(
"widgetusers/<int:pk>/details",
views.WidgetUserDetailView.as_view(),
name="user-detail",
),
path(
"widgetusers/add",
views.WidgetUserDetailView.as_view(),
name="user-add",
),
]
......
# from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import UpdateView, CreateView
from .models import WidgetUser
from django.shortcuts import render
......@@ -14,3 +16,16 @@ def dashboard(request):
users = WidgetUser.objects.all()
context = {"users": users}
return render(request, "dashboard/dashboard.html", context)
class WidgetUserDetailView(DetailView):
model = WidgetUser
template_name = "dashboard/widgetuser-details.html"
class WidgetUserUpdateView(UpdateView):
model = WidgetUser
class WidgetUserCreateView(CreateView):
model = WidgetUser
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