Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
d1b04e92
Commit
d1b04e92
authored
Apr 15, 2020
by
Jonathan Christopher Jakub
Browse files
Fix: set author on case_subject to reduce chaining the author value from case
parent
1c7f17d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/cases/migrations/0004_casesubject_author.py
0 → 100644
View file @
d1b04e92
# Generated by Django 3.0.1 on 2020-04-15 11:36
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'accounts'
,
'0001_initial'
),
(
'cases'
,
'0003_auto_20200414_1453'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'casesubject'
,
name
=
'author'
,
field
=
models
.
ForeignKey
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
DO_NOTHING
,
related_name
=
'case_subject'
,
to
=
'accounts.Account'
),
),
]
apps/cases/models.py
View file @
d1b04e92
...
...
@@ -21,6 +21,13 @@ class CaseSubject(models.Model):
deleted_at
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
is_active
=
models
.
BooleanField
(
default
=
True
,
db_index
=
True
)
author
=
models
.
ForeignKey
(
Account
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
DO_NOTHING
,
related_name
=
"case_subject"
,
)
objects
=
SoftObjectManager
()
...
...
apps/cases/views.py
View file @
d1b04e92
...
...
@@ -63,18 +63,25 @@ class CaseSubjectViewSet(viewsets.ViewSet):
def
create
(
self
,
request
):
serializer
=
self
.
serializer_class
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
save
()
serializer_data
=
serializer
.
data
instance
=
CaseSubject
.
objects
.
create
(
**
serializer_data
,
author
=
request
.
user
.
account
)
# Add case subject creation log
Log
.
objects
.
create
(
model_name
=
MODEL_NAME_CASE_SUBJECT
,
object_id
=
serializer
.
data
[
"
subject_id
"
]
,
revision_id
=
serializer
.
data
[
"
revision_id
"
]
,
object_id
=
instance
.
subject_id
,
revision_id
=
instance
.
revision_id
,
action_type
=
ACTIVITY_TYPE_CREATE
,
author
=
request
.
user
.
account
,
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
,)
return
Response
(
self
.
serializer_class
(
instance
).
data
,
status
=
status
.
HTTP_201_CREATED
,
)
def
update
(
self
,
request
,
pk
=
None
):
previous_instance
=
get_object_or_404
(
self
.
queryset
,
pk
=
pk
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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