Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_jupert
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joseph Izon
widget_jupert
Commits
0191f2d7
Commit
0191f2d7
authored
Apr 07, 2022
by
Joseph Izon
💀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created the Department Model and Added the id_num and email field in the existing WidgerUser model
parent
4af4f941
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
4 deletions
+47
-4
db.sqlite3
widget_jupert/db.sqlite3
+0
-0
admin.py
widget_jupert/homepage/admin.py
+11
-2
models.py
widget_jupert/homepage/models.py
+19
-1
views.py
widget_jupert/homepage/views.py
+17
-1
No files found.
widget_jupert/db.sqlite3
View file @
0191f2d7
No preview for this file type
widget_jupert/homepage/admin.py
View file @
0191f2d7
from
django.contrib
import
admin
from
django.contrib
import
admin
# Register your models here.
# Register your models here.
from
.models
import
WidgetUser
from
.models
import
Department
,
WidgetUser
class
WidgetUserAdmin
(
admin
.
ModelAdmin
):
class
WidgetUserAdmin
(
admin
.
ModelAdmin
):
model
=
WidgetUser
model
=
WidgetUser
search_fields
=
(
'first_name'
,
'last_name'
,)
search_fields
=
(
'first_name'
,
'last_name'
,)
list_display
=
(
'first_name'
,
'middle_name'
,
'last_name'
,)
list_display
=
(
'
id_num'
,
'
first_name'
,
'middle_name'
,
'last_name'
,)
list_filter
=
(
'first_name'
,
'middle_name'
,
'last_name'
,)
list_filter
=
(
'first_name'
,
'middle_name'
,
'last_name'
,)
class
DepartmentAdmin
(
admin
.
ModelAdmin
):
model
=
Department
search_fields
=
(
'dept_name'
,
'home_unit'
,)
list_display
=
(
'dept_name'
,
'home_unit'
,)
list_filter
=
(
'dept_name'
,
'home_unit'
,)
admin
.
site
.
register
(
WidgetUser
,
WidgetUserAdmin
)
admin
.
site
.
register
(
WidgetUser
,
WidgetUserAdmin
)
admin
.
site
.
register
(
Department
,
DepartmentAdmin
)
widget_jupert/homepage/models.py
View file @
0191f2d7
...
@@ -7,5 +7,23 @@ class WidgetUser(models.Model):
...
@@ -7,5 +7,23 @@ class WidgetUser(models.Model):
middle_name
=
models
.
CharField
(
max_length
=
50
)
middle_name
=
models
.
CharField
(
max_length
=
50
)
last_name
=
models
.
CharField
(
max_length
=
50
)
last_name
=
models
.
CharField
(
max_length
=
50
)
id_num
=
models
.
CharField
(
max_length
=
7
)
email
=
models
.
EmailField
(
max_length
=
100
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
last_name
return
self
.
last_name
class
Department
(
models
.
Model
):
#Two Parameters (Model to which the Association is being made, process that you want to be done when a particular model is deleted)
user
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
dept_name
=
models
.
CharField
(
max_length
=
50
)
home_unit
=
models
.
CharField
(
max_length
=
50
)
#so that when calling the objects of the department, the title would be displayed instead of a number
def
__str__
(
self
):
return
self
.
dept_name
widget_jupert/homepage/views.py
View file @
0191f2d7
from
urllib
import
response
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
homepage.models
import
WidgetUser
from
homepage.models
import
Department
# Create your views here.
# Create your views here.
def
index
(
request
):
def
index
(
request
):
return
HttpResponse
(
"Welcome to the Widget's Home Page!"
)
widgetuser_objects
=
WidgetUser
.
objects
.
all
()
\ No newline at end of file
department_objects
=
Department
.
objects
.
all
()
title
=
"Welcome to the Widget's Home Page!<br><br>"
response
=
"WIDGET USERS:<br>"
for
dept
in
department_objects
:
response
=
(
response
+
f
"{dept.user.last_name}, {dept.user.first_name} {dept.user.middle_name}: "
+
f
"{dept.user.id_num}, {dept.user.email}, "
+
f
"{dept.dept_name}, {dept.home_unit}<br>"
)
return
HttpResponse
(
title
+
response
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment