Commit b6d3d47d authored by Stefan Gomez's avatar Stefan Gomez

Implemented the 'Add New Widget User Page'.

parent 4ea9aa33
# Generated by Django 4.1.6 on 2023-05-08 17:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.department', verbose_name='Department, Home Unit'),
),
migrations.AlterField(
model_name='widgetuser',
name='first_name',
field=models.CharField(max_length=100, verbose_name='First Name'),
),
migrations.AlterField(
model_name='widgetuser',
name='last_name',
field=models.CharField(max_length=100, verbose_name='Last Name'),
),
migrations.AlterField(
model_name='widgetuser',
name='middle_name',
field=models.CharField(max_length=100, verbose_name='Middle Name'),
),
]
...@@ -11,10 +11,10 @@ class Department(models.Model): ...@@ -11,10 +11,10 @@ class Department(models.Model):
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=100) first_name = models.CharField(max_length=100, verbose_name='First Name')
middle_name = models.CharField(max_length=100) middle_name = models.CharField(max_length=100, verbose_name='Middle Name')
last_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100, verbose_name='Last Name')
department = models.ForeignKey(Department, on_delete=models.CASCADE) department = models.ForeignKey(Department, on_delete=models.CASCADE, verbose_name='Department, Home Unit')
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)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</h3> </h3>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<a href="/widgetusers/add"><input type="submit" value="Add Widget User"></a><br><br> <a href="/dashboard/add"><input type="submit" value="Add Widget User"></a><br>
<a href="/announcement">Announcement Board</a><br> <a href="/announcement">Announcement Board</a><br>
<a href="/forum">Forum</a><br> <a href="/forum">Forum</a><br>
<a href="/assignments">Assignments</a><br> <a href="/assignments">Assignments</a><br>
......
{% extends 'base.html' %}
{% block title %}Add Widget User{% endblock %}
{% block content %}
<h1>Add a new Widget user:</h1>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Widget User">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from .views import index, WidgetUserDetailView from .views import index, WidgetUserDetailView, WidgetUserCreateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('<int:pk>/details', WidgetUserDetailView.as_view(), name='widgetuser-details'), path('<int:pk>/details', WidgetUserDetailView.as_view(), name='widgetuser-details'),
path('add/', WidgetUserCreateView.as_view(), name='add-widgetuser'),
] ]
app_name = "dashboard" app_name = "dashboard"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from.models import WidgetUser from.models import WidgetUser
...@@ -12,4 +13,10 @@ class WidgetUserDetailView(DetailView): ...@@ -12,4 +13,10 @@ class WidgetUserDetailView(DetailView):
model = WidgetUser model = WidgetUser
def get(self, request, pk): def get(self, request, pk):
return render(request, 'dashboard/widgetuser-details.html', {'widgetuser': self.model.objects.get(pk=pk)}) return render(request, 'dashboard/widgetuser-details.html', {'widgetuser': self.model.objects.get(pk=pk)})
\ No newline at end of file
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
template_name = 'dashboard/widgetuser-add.html'
\ No newline at end of file
No preview for this file type
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