Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_vincentdjango
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
1
Merge Requests
1
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
Almira Redoble
midterm_vincentdjango
Commits
bbab1cb3
Commit
bbab1cb3
authored
Mar 05, 2023
by
Jayson Lim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated model class and its attributes, also updated the implementation of view
parent
7cc4c2cc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
20 deletions
+18
-20
models.cpython-39.pyc
...jango/announcementBoard/__pycache__/models.cpython-39.pyc
+0
-0
views.cpython-39.pyc
...django/announcementBoard/__pycache__/views.cpython-39.pyc
+0
-0
models.py
widget_vincentdjango/announcementBoard/models.py
+10
-5
views.py
widget_vincentdjango/announcementBoard/views.py
+8
-15
db.sqlite3
widget_vincentdjango/db.sqlite3
+0
-0
No files found.
widget_vincentdjango/announcementBoard/__pycache__/models.cpython-39.pyc
View file @
bbab1cb3
No preview for this file type
widget_vincentdjango/announcementBoard/__pycache__/views.cpython-39.pyc
View file @
bbab1cb3
No preview for this file type
widget_vincentdjango/announcementBoard/models.py
View file @
bbab1cb3
from
django.db
import
models
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
dashboard.models
import
WidgetUser
class
Announcement
(
models
.
Model
):
class
Announcement
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
250
,
default
=
""
)
title
=
models
.
CharField
(
max_length
=
250
,
default
=
""
)
body
=
models
.
TextField
(
null
=
True
,
blank
=
True
)
body
=
models
.
TextField
(
null
=
True
,
blank
=
True
)
...
@@ -8,9 +9,9 @@ class Announcement(models.Model):
...
@@ -8,9 +9,9 @@ class Announcement(models.Model):
WidgetUser
,
WidgetUser
,
null
=
True
,
null
=
True
,
default
=
True
,
default
=
True
,
on_delete
=
models
.
SET_DEFAULT
,
on_delete
=
models
.
CASCADE
,
related_name
=
'announcements'
,
)
)
pub_datetime
=
models
.
DateTimeField
(
auto_now_add
=
True
)
pub_datetime
=
models
.
DateTimeField
(
auto_now_add
=
True
)
def
__str__
(
self
):
def
__str__
(
self
):
...
@@ -20,14 +21,18 @@ class Announcement(models.Model):
...
@@ -20,14 +21,18 @@ class Announcement(models.Model):
return
self
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y
%
I:
%
M
%
p'
)
return
self
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y
%
I:
%
M
%
p'
)
class
Reaction
(
models
.
Model
):
class
Reaction
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
5
,
default
=
''
)
name
=
models
.
CharField
(
max_length
=
5
,
choices
=
[(
'Like'
,
'Like'
),
(
'Love'
,
'Love'
),
(
'Angry'
,
'Angry'
)],
default
=
'Like'
)
tally
=
models
.
PositiveIntegerField
(
default
=
0
)
tally
=
models
.
PositiveIntegerField
(
default
=
0
)
annoucement
=
models
.
ForeignKey
(
annoucement
=
models
.
ForeignKey
(
Announcement
,
Announcement
,
null
=
True
,
null
=
True
,
default
=
True
,
default
=
True
,
on_delete
=
models
.
SET_DEFAULT
on_delete
=
models
.
CASCADE
,
related_name
=
'reactions'
)
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
widget_vincentdjango/announcementBoard/views.py
View file @
bbab1cb3
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
Announcement
from
.models
import
Announcement
from
.models
import
Reaction
from
dashboard.models
import
WidgetUser
def
index
(
request
):
def
index
(
request
):
...
@@ -13,26 +13,19 @@ def index(request):
...
@@ -13,26 +13,19 @@ def index(request):
body
=
"<h2>Announcements:</h2>"
body
=
"<h2>Announcements:</h2>"
announcements
=
Announcement
.
objects
.
all
()
for
x
in
Announcement
.
objects
.
all
():
reactions
=
Reaction
.
objects
.
all
()
reaction
=
x
.
reactions
.
all
()
for
i
in
range
(
0
,
len
(
announcements
),
1
):
announcement
=
announcements
[
i
]
body
+=
"<p style='border: 2px solid gray;
\
body
+=
"<p style='border: 2px solid gray;
\
border-radius:5px;
\
border-radius:5px;
\
padding:20px 30px;'>
\
padding:20px 30px;'>
\
{} by {} published {}:
\
{} by {} published {}:
\
<br>
\
<br>
\
{}
\
{}
\
</p>"
.
format
(
announcement
.
title
,
announcement
.
author
,
</p>"
.
format
(
x
.
title
,
x
.
author
,
announcement
.
format_pub_datetime
(),
announcement
.
body
)
x
.
format_pub_datetime
(),
x
.
body
)
for
y
in
reaction
:
for
j
in
range
(
i
*
3
,
(
i
+
1
)
*
3
):
if
j
>=
len
(
reactions
):
break
reaction
=
reactions
[
j
]
body
+=
"<p>{}: {}
\
body
+=
"<p>{}: {}
\
</p>"
.
format
(
reaction
.
name
,
reaction
.
tally
)
</p>"
.
format
(
y
.
name
,
y
.
tally
)
body
+=
'<p> </p>'
body
+=
'<p> </p>'
...
...
widget_vincentdjango/db.sqlite3
View file @
bbab1cb3
No preview for this file type
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