Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julien Jerphanion
Rex Dri
Commits
c0c08869
Commit
c0c08869
authored
Sep 05, 2018
by
Florent Chehab
Browse files
Add a bypass option in the dictmodeview
parent
0d2b5992
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/models/tools/DictModeViewSet.py
View file @
c0c08869
...
...
@@ -6,12 +6,14 @@ class DictModeViewSet(viewsets.ModelViewSet):
ViewSet that renders data as dict with keys corresponding to the model
primary key. Instead of list.
"""
BYPASS_DICT_MODE
=
False
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
super
(
viewsets
.
ModelViewSet
,
self
).
list
(
# pylint: disable=E1003
request
,
*
args
,
**
kwargs
)
# call the original 'list'
pk_attr_name
=
self
.
serializer_class
.
Meta
.
model
.
_meta
.
pk
.
name
response
.
data
=
{
d
[
pk_attr_name
]:
d
for
d
in
response
.
data
}
if
not
self
.
BYPASS_DICT_MODE
:
pk_attr_name
=
self
.
serializer_class
.
Meta
.
model
.
_meta
.
pk
.
name
response
.
data
=
{
d
[
pk_attr_name
]:
d
for
d
in
response
.
data
}
return
response
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