Commit c5662e9f authored by Mavrick Jordan Lee's avatar Mavrick Jordan Lee

Added Widget User Details Page. Updated models to add get_absolute_url...

Added Widget User Details Page. Updated models to add get_absolute_url function. Updated urls and views. Updated dashboard.html to make widget user name a link.
parent 8b56b8e8
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
...@@ -17,3 +18,6 @@ class WidgetUser(models.Model): ...@@ -17,3 +18,6 @@ class WidgetUser(models.Model):
def __str__(self): def __str__(self):
return self.first_name return self.first_name
def get_absolute_url(self):
return reverse('dashboard:widgetuser-detail', kwargs={'pk': self.pk})
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
<h1>Welcome to Widget!</h1> <h1>Welcome to Widget!</h1>
<h2>Widget Users:</h2> <h2>Widget Users:</h2>
{% for user in widget_users %} {% for user in widget_users %}
{{user.last_name}}, {{user.first_name}}<br> <a href="{% url 'dashboard:widgetuser-details' user.id %}">
{{user.last_name}}, {{user.first_name}}
</a><br>
{% endfor %} {% endfor %}
<br><button>Add Widget User</button><br><br> <br><button>Add Widget User</button><br><br>
Announcement Board <br> Announcement Board <br>
......
{% extends 'base.html' %}
{% block title %}{{ object.last_name }}, {{ object.first_name }}{% endblock %}
{% block content %}
<h1>{{ object.first_name }} {{object.middle_name}} {{ object.last_name }}</h1>
<p>
{{ object.user_department.dept_name }}<br>
{{ object.user_department.home_unit }}
</p>
<button>Edit Widget User</button>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
from .views import (
WidgetUserDetailsView
)
urlpatterns = [ urlpatterns = [
path('dashboard/', views.dashboard, name = "dashboard"), path('dashboard/', views.dashboard, name = "dashboard"),
path('widgetusers/<int:pk>/details/', WidgetUserDetailsView.as_view(), name = "widgetuser-details"),
] ]
app_name = 'dashboard'
\ No newline at end of file
from .models import Department, WidgetUser from .models import Department, WidgetUser
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView
# Create your views here. # Create your views here.
def dashboard(request): def dashboard(request):
widget_users = WidgetUser.objects.all() widget_users = WidgetUser.objects.all()
context = {"widget_users": widget_users} context = {"widget_users": widget_users}
return render(request, 'dashboard/dashboard.html', context) return render(request, 'dashboard/dashboard.html', context)
class WidgetUserDetailsView(DetailView):
model = WidgetUser
template_name = 'dashboard/widgetuser-details.html'
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