Commit 25b155a2 authored by Fritzie Dianne Del Pilar's avatar Fritzie Dianne Del Pilar
parents 338c18ad 8e98ab70
from django.db import models from django.db import models
from django.urls import reverse
class Department(models.Model): class Department(models.Model):
...@@ -17,3 +18,6 @@ class WidgetUser(models.Model): ...@@ -17,3 +18,6 @@ class WidgetUser(models.Model):
def __str__(self): def __str__(self):
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name) return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
def get_absolute_url(self):
return reverse('dashboard:widgetuser-details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}Widget v2{% endblock %}
{% block heading %} <h1> Welcome to Widget! </h1> {% endblock %}
{% block content %}
<p>
Widget Users:<br>
{% for user in users %}
<a href="{{ user.get_absolute_url }}">{{ user.last_name }}, {{ user.first_name }}</a><br>
{% endfor %}
</p>
{% endblock %}
{% block footing %}
<p class="centerB">
<a href="{% url 'dashboard:widgetuser-create' %}">
<button class="btn add">Add Widget User</button>
</a>
</p>
<p>
<a href="/announcement_board/" class="link">Announcement Board</a><br>
<a href="/forum/" class="link">Forum</a><br>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}Add Widget User{% endblock %}
{% block heading %} <h1> Add a new Widget User: </h1> {% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<p class="centerB">
<input class="submitB" type="submit" value="Add Widget User">
</p>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}{{ object.last_name }}, {{ object.first_name }}{% endblock %}
{% block heading %} <h1> {{ object.first_name }} {{ object.middle_name }} {{ object.last_name }} </h1> {% endblock %}
{% block content %}
<p>
{{ object.department.dept_name }}<br>
{{ object.department.home_unit }}<br>
</p>
{% endblock %}
{% block footing %}
<p class="centerB">
<a href="{% url 'dashboard:widgetuser-update' object.pk %}">
<button class="btn edit">Edit Widget User</button>
</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block page-title %}Edit Widget User{% endblock %}
{% block heading %} <h1> Edit Widget User: </h1> {% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<p class="centerB">
<input class="submitB" type="submit" value="Save Changes to Widget User">
</p>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import (dashboard, WidgetUserDetailView, WidgetUserCreateView, WidgetUserUpdateView)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path ('dashboard/', dashboard, name='dashboard'),
path ('widgetusers/<int:pk>/details', WidgetUserDetailView.as_view(), name='widgetuser-details'),
path ('widgetusers/add', WidgetUserCreateView.as_view(), name='widgetuser-create'),
path ('widgetusers/<int:pk>/edit', WidgetUserUpdateView.as_view(), name='widgetuser-update')
] ]
app_name = "dashboard" app_name = "dashboard"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Department, WidgetUser from .models import WidgetUser
def index (request): def dashboard(request):
return_string = '<p>Welcome to Widget!</p> WIDGET USERS:<br>' users = WidgetUser.objects.all()
for user in WidgetUser.objects.all(): return render(request, 'dashboard/dashboard.html', {'users': users})
return_string += '{}, {} {}: {}, {}<br>'.format(
user.last_name, user.first_name, user.middle_name, user.department.dept_name, user.department.home_unit
) class WidgetUserDetailView(DetailView):
html_string = '<html><body>{}</body></html>'.format(return_string) model = WidgetUser
return HttpResponse(html_string) template_name = 'dashboard/widgetuser-details.html'
\ No newline at end of file
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-add.html'
class WidgetUserUpdateView(UpdateView):
model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-edit.html'
# Generated by Django 4.2.1 on 2023-05-15 16:26
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('forum', '0002_auto_20230306_0546'),
('forum', '0003_alter_reply_pub_datetime'),
]
operations = [
]
...@@ -19,6 +19,6 @@ from django.urls import path, include ...@@ -19,6 +19,6 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('announcement_board/', include('announcement_board.urls', namespace='announcement_board')), path('announcement_board/', include('announcement_board.urls', namespace='announcement_board')),
path('dashboard/', include('dashboard.urls', namespace="dashboard")), path('', include('dashboard.urls', namespace="dashboard")),
path('forum/', include('forum.urls', namespace="forum")), path('forum/', include('forum.urls', namespace="forum")),
] ]
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