Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_group3
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
Jonathan Talbot
widget_group3
Commits
70b0fc23
Commit
70b0fc23
authored
Apr 07, 2022
by
iceman2434
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified forum class and added reply class
Changed forum class name to post Added reply class
parent
d7c88b7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
20 deletions
+72
-20
admin.py
widget_group3/widget_group3/admin.py
+40
-12
models.py
widget_group3/widget_group3/models.py
+23
-5
urls.py
widget_group3/widget_group3/urls.py
+1
-1
views.py
widget_group3/widget_group3/views.py
+8
-2
No files found.
widget_group3/widget_group3/admin.py
View file @
70b0fc23
from
django.contrib
import
admin
from
django.contrib
import
admin
from
.models
import
WidgetUser
,
Forum
,
Announcement
,
Assign
ment
from
.models
import
WidgetUser
,
Post
,
Reply
,
Announcement
,
Assignment
,
Depart
ment
# Classes
# Classes
class
DepartmentInline
(
admin
.
TabularInline
):
model
=
Department
class
WidgetUserAdmin
(
admin
.
ModelAdmin
):
class
WidgetUserAdmin
(
admin
.
ModelAdmin
):
model
=
WidgetUser
model
=
WidgetUser
search_fields
=
(
'first_name'
,
'middle_name'
,
'last_name'
)
list_display
=
(
'first_name'
,
'middle_name'
,
'last_name'
)
list_filter
=
(
'first_name'
,
'middle_name'
,
'last_name'
)
fieldsets
=
[
fieldsets
=
[
(
'Widget User Data'
,
{
(
'Widget User Data'
,
{
'fields'
:
[
'fields'
:
[
'id_num'
,
'first_name'
,
'first_name'
,
'middle_name'
,
'middle_name'
,
'last_name'
'last_name'
'last_name'
,
'email'
]
]
}),
}),
]
]
inlines
=
[
DepartmentInline
,]
class
DepartmentAdmin
(
admin
.
ModelAdmin
):
model
=
Department
class
AnnouncementAdmin
(
admin
.
ModelAdmin
):
class
AnnouncementAdmin
(
admin
.
ModelAdmin
):
model
=
Announcement
model
=
Announcement
...
@@ -38,22 +44,43 @@ class AnnouncementAdmin(admin.ModelAdmin):
...
@@ -38,22 +44,43 @@ class AnnouncementAdmin(admin.ModelAdmin):
})
})
]
]
class
ForumAdmin
(
admin
.
ModelAdmin
):
class
ReplyInline
(
admin
.
TabularInline
):
model
=
Forum
model
=
Reply
search_fields
=
(
'post_title'
,
'post_body'
,
'pub_date'
)
class
PostAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'post_title'
,
'post_body'
,
'pub_date'
)
model
=
Post
list_filter
=
(
'post_title'
,
'post_body'
,
'pub_date'
)
search_fields
=
(
'post_title'
,
'post_body'
,
'pub_date'
,
'author'
)
list_display
=
(
'post_title'
,
'post_body'
,
'pub_date'
,
'author'
)
list_filter
=
(
'post_title'
,
'post_body'
,
'pub_date'
,
'author'
)
fieldsets
=
[
fieldsets
=
[
(
'
Forum
Data'
,
{
(
'
Post
Data'
,
{
'fields'
:
[
'fields'
:
[
'post_title'
,
'post_title'
,
'post_body'
,
'post_body'
,
'author'
,
]
]
}),
}),
]
]
inlines
=
[
ReplyInline
,]
class
ReplyAdmin
(
admin
.
ModelAdmin
):
model
=
Reply
search_fields
=
(
'reply_body'
,
'pub_date'
,
'author'
)
list_display
=
(
'reply_body'
,
'pub_date'
,
'author'
)
list_filter
=
(
'reply_body'
,
'pub_date'
,
'author'
)
fieldsets
=
[
(
'Reply Data'
,
{
'fields'
:
[
'reply_body'
,
'author'
,
]
}),
]
class
AssignmentAdmin
(
admin
.
ModelAdmin
):
class
AssignmentAdmin
(
admin
.
ModelAdmin
):
model
=
Assignment
model
=
Assignment
...
@@ -87,6 +114,7 @@ class AssignmentAdmin(admin.ModelAdmin):
...
@@ -87,6 +114,7 @@ class AssignmentAdmin(admin.ModelAdmin):
# Register models
# Register models
admin
.
site
.
register
(
WidgetUser
,
WidgetUserAdmin
)
admin
.
site
.
register
(
WidgetUser
,
WidgetUserAdmin
)
admin
.
site
.
register
(
Forum
,
ForumAdmin
)
admin
.
site
.
register
(
Post
,
PostAdmin
)
admin
.
site
.
register
(
Reply
,
ReplyAdmin
)
admin
.
site
.
register
(
Announcement
,
AnnouncementAdmin
)
admin
.
site
.
register
(
Announcement
,
AnnouncementAdmin
)
admin
.
site
.
register
(
Assignment
,
AssignmentAdmin
)
admin
.
site
.
register
(
Assignment
,
AssignmentAdmin
)
widget_group3/widget_group3/models.py
View file @
70b0fc23
...
@@ -2,20 +2,29 @@ from django.db import models
...
@@ -2,20 +2,29 @@ from django.db import models
from
django.urls
import
reverse
from
django.urls
import
reverse
class
WidgetUser
(
models
.
Model
):
class
WidgetUser
(
models
.
Model
):
id_num
=
models
.
IntegerField
()
first_name
=
models
.
CharField
(
max_length
=
100
)
first_name
=
models
.
CharField
(
max_length
=
100
)
middle_name
=
models
.
CharField
(
max_length
=
100
)
middle_name
=
models
.
CharField
(
max_length
=
100
)
last_name
=
models
.
CharField
(
max_length
=
100
)
last_name
=
models
.
CharField
(
max_length
=
100
)
email
=
models
.
EmailField
()
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
full_name
return
'{}, {} {}: {}, {}'
.
format
(
self
.
last_name
,
self
.
first_name
,
self
.
middle_name
,
self
.
id_num
,
self
.
email
)
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
reverse
(
'widget_user'
,
args
=
[(
self
.
full_name
)])
return
reverse
(
'widget_user'
,
args
=
[(
self
.
full_name
)])
@
property
def
full_name
(
self
):
def
full_name
(
self
):
return
'{} {} {}'
.
format
(
self
.
first_name
,
self
.
middle_name
,
self
.
last_name
)
return
'{} {} {}'
.
format
(
self
.
first_name
,
self
.
middle_name
,
self
.
last_name
)
class
Department
(
models
.
Model
):
dept_name
=
models
.
CharField
(
max_length
=
100
)
home_unit
=
models
.
CharField
(
max_length
=
100
)
widget_user
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
return
'{}, {}'
.
format
(
self
.
dept_name
,
self
.
home_unit
)
class
Announcement
(
models
.
Model
):
class
Announcement
(
models
.
Model
):
announcement_title
=
models
.
CharField
(
max_length
=
50
)
announcement_title
=
models
.
CharField
(
max_length
=
50
)
announcement_body
=
models
.
CharField
(
max_length
=
200
)
announcement_body
=
models
.
CharField
(
max_length
=
200
)
...
@@ -31,18 +40,27 @@ class Announcement(models.Model):
...
@@ -31,18 +40,27 @@ class Announcement(models.Model):
def
full_announcement
(
self
):
def
full_announcement
(
self
):
return
'{} {} {}'
.
format
(
self
.
announcement_title
,
self
.
announcement_body
,
self
.
pub_date
)
return
'{} {} {}'
.
format
(
self
.
announcement_title
,
self
.
announcement_body
,
self
.
pub_date
)
class
Post
(
models
.
Model
):
class
Forum
(
models
.
Model
):
post_title
=
models
.
CharField
(
max_length
=
50
)
post_title
=
models
.
CharField
(
max_length
=
50
)
post_body
=
models
.
CharField
(
max_length
=
100
)
post_body
=
models
.
CharField
(
max_length
=
100
)
pub_date
=
models
.
DateTimeField
(
auto_now_add
=
True
,
editable
=
False
)
pub_date
=
models
.
DateTimeField
(
auto_now_add
=
True
,
editable
=
False
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
post_title
return
'{} by {} dated {}:
\n
{}'
.
format
(
self
.
post_title
,
self
.
author
.
get_absolute_url
(),
self
.
pub_date
,
self
.
post_body
)
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
reverse
(
'forum'
,
args
=
[(
self
.
post_title
)])
return
reverse
(
'forum'
,
args
=
[(
self
.
post_title
)])
class
Reply
(
models
.
Model
):
reply_body
=
models
.
CharField
(
max_length
=
100
)
pub_date
=
models
.
DateTimeField
(
auto_now_add
=
True
,
editable
=
False
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
replied_post
=
models
.
ForeignKey
(
Post
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
return
'Reply by {} dated {}:
\n
{}'
.
format
(
self
.
author
.
get_absolute_url
(),
self
.
pub_date
,
self
.
reply_body
)
class
Assignment
(
models
.
Model
):
class
Assignment
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
name
=
models
.
CharField
(
max_length
=
100
)
description
=
models
.
CharField
(
max_length
=
200
)
description
=
models
.
CharField
(
max_length
=
200
)
...
...
widget_group3/widget_group3/urls.py
View file @
70b0fc23
...
@@ -22,5 +22,5 @@ urlpatterns = [
...
@@ -22,5 +22,5 @@ urlpatterns = [
path
(
''
,
homepage
,
name
=
'homepage'
),
path
(
''
,
homepage
,
name
=
'homepage'
),
path
(
'assignments/'
,
assignments
,
name
=
'assignments'
),
path
(
'assignments/'
,
assignments
,
name
=
'assignments'
),
path
(
'announcements/'
,
announcements
,
name
=
'Announcement Board'
),
path
(
'announcements/'
,
announcements
,
name
=
'Announcement Board'
),
path
(
'forum/'
,
forum
,
name
=
'
f
orum'
)
path
(
'forum/'
,
forum
,
name
=
'
F
orum'
)
]
]
widget_group3/widget_group3/views.py
View file @
70b0fc23
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
WidgetUser
,
Post
,
Reply
,
Announcement
,
Assignment
,
Department
def
homepage
(
request
):
def
homepage
(
request
):
return
HttpResponse
(
'Welcome to Widget!'
)
widget_users
=
WidgetUser
.
objects
.
all
()
output
=
"WIDGET USERS:
\n
"
+
"
\n
"
.
join
([
str
(
user
)
for
user
in
widget_users
])
return
HttpResponse
(
output
,
content_type
=
"text/plain"
)
def
assignments
(
request
):
def
assignments
(
request
):
return
HttpResponse
(
'This is the Assignments page!'
)
return
HttpResponse
(
'This is the Assignments page!'
)
...
@@ -10,4 +13,7 @@ def announcements(request):
...
@@ -10,4 +13,7 @@ def announcements(request):
return
HttpResponse
(
'This is the Announcement Board!'
)
return
HttpResponse
(
'This is the Announcement Board!'
)
def
forum
(
request
):
def
forum
(
request
):
return
HttpResponse
(
'Welcome to Widget’s Forum!'
)
post
=
Post
.
objects
.
all
()
reply
=
Reply
.
objects
.
all
()
output
=
"FORUM POSTS:
\n
"
+
"
\n
"
.
join
([
str
(
x
)
for
x
in
post
])
+
"
\n
"
.
join
([
str
(
z
)
for
z
in
reply
])
return
HttpResponse
(
output
,
content_type
=
"text/plain"
)
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