Commit 63572b8e authored by justin's avatar justin

feat: added DetailViews per user

parent bc58a526
from django.db import models from django.db import models
from django.urls import reverse
class Department(models.Model): class Department(models.Model):
...@@ -23,3 +24,9 @@ class WidgetUser(models.Model): ...@@ -23,3 +24,9 @@ class WidgetUser(models.Model):
def displayName(self): def displayName(self):
return f"{self.first_name} {self.last_name}" 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 @@ ...@@ -4,7 +4,7 @@
<h2>Widget Users:</h2> <h2>Widget Users:</h2>
<ul> <ul>
{% for user in users %} {% for user in users %}
<a href=""> <a href="{{user.get_absolute_url}}">
<li>{{ user.last_name }}, {{ user.first_name }}</li> <li>{{ user.last_name }}, {{ user.first_name }}</li>
</a> </a>
{% endfor %} {% 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 ...@@ -4,6 +4,16 @@ from . import views
urlpatterns = [ urlpatterns = [
path("", views.dashboard, name="dashboard"), 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.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import UpdateView, CreateView
from .models import WidgetUser from .models import WidgetUser
from django.shortcuts import render from django.shortcuts import render
...@@ -14,3 +16,16 @@ def dashboard(request): ...@@ -14,3 +16,16 @@ def dashboard(request):
users = WidgetUser.objects.all() users = WidgetUser.objects.all()
context = {"users": users} context = {"users": users}
return render(request, "dashboard/dashboard.html", context) 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