Commit b694ca00 authored by Almira Redoble's avatar Almira Redoble

Implemented per widget user details page. To do this, a class-based view that...

Implemented per widget user details page. To do this, a class-based view that inherited from DetailView was made. The url for this view was then configured in urls.py, and a template was made for the page.
parent 92f042e7
...@@ -18,6 +18,7 @@ https://www.w3schools.com/html/html_css.asp ...@@ -18,6 +18,7 @@ https://www.w3schools.com/html/html_css.asp
https://www.w3schools.com/html/html_styles.asp https://www.w3schools.com/html/html_styles.asp
https://github.com/github/gitignore/blob/main/Python.gitignore; https://github.com/github/gitignore/blob/main/Python.gitignore;
https://www.onespacemedia.com/news/getting-started-generic-class-based-views-django/ https://www.onespacemedia.com/news/getting-started-generic-class-based-views-django/
https://www.w3docs.com/snippets/html/how-to-create-an-html-button-that-acts-like-a-link.html
(sgd) Joaquin Crisologo, 28 February, 2023 (sgd) Joaquin Crisologo, 28 February, 2023
(sgd) Andrew Idquival, 28 February, 2023 (sgd) Andrew Idquival, 28 February, 2023
......
from django.db import models from django.db import models
from django.urls import reverse
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length=100, default="") dept_name = models.CharField(max_length=100, default="")
...@@ -25,3 +25,6 @@ class WidgetUser(models.Model): ...@@ -25,3 +25,6 @@ class WidgetUser(models.Model):
self.first_name, self.first_name,
self.middle_name self.middle_name
) )
def get_absolute_url(self):
return reverse('dashboard:user-details', kwargs={'pk': self.pk})
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
<title>{% block title %}{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
</head> </head>
<body> <body>
<div id="heading"> <div class="heading">
{% block heading %}{% endblock %} {% block heading %}{% endblock %}
</div> </div>
<div id="content"> <div class="content">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
</body> </body>
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
{% block title %}Widget v2{% endblock %} {% block title %}Widget v2{% endblock %}
{% block heading %}Welcome to Widget!{% endblock %} {% block heading %}Welcome to Widget!{% endblock %}
{% block content %} {% block content %}
<p div="heading">Widget Users:</p> <p id="subheading">Widget Users:</p>
<ul> <ul>
{% for user in users %} {% for user in users %}
<li> <li>
<a href="#"> <a href="{{ user.get_absolute_url }}">
{{ user.last_name }}, {{ user.first_name }}</a> {{ user.last_name }}, {{ user.first_name }}</a>
</li> </li>
{% endfor %} {% endfor %}
......
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.last_name }}, {{ object.first_name }}{% endblock %}
{% block heading %}
<p id="uppercase">
{{ object.first_name }}
{{ object.middle_name }}
{{ object.last_name }}
</p>
{% endblock %}
{% block content %}
<p> {{ object.department.dept_name }} </p>
<p> {{ object.department.home_unit }} </p>
<button onclick="window.location.href='#';">
Edit Widget User
</button>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import index, UserDetailView
urlpatterns = [ urlpatterns = [
path('dashboard/', index, name='index'), path('dashboard/', index, name='index'),
path('widgetusers/<int:pk>/details/', UserDetailView.as_view(), name='user-details'),
] ]
......
...@@ -7,3 +7,7 @@ from .models import WidgetUser ...@@ -7,3 +7,7 @@ from .models import WidgetUser
def index(request): def index(request):
users = WidgetUser.objects.all() users = WidgetUser.objects.all()
return render(request, 'dashboard/dashboard.html', {'users': users, }) return render(request, 'dashboard/dashboard.html', {'users': users, })
class UserDetailView(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