Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
0d2b5992
Commit
0d2b5992
authored
Sep 05, 2018
by
Florent Chehab
Browse files
Tweak to force the presence of an id field in server data
parent
05513735
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/models/my_model/myModelSerializer.py
View file @
0d2b5992
...
...
@@ -33,6 +33,10 @@ class MyModelSerializer(MySerializerWithJSON):
pending_moderation
=
serializers
.
SerializerMethodField
()
model_config
=
serializers
.
SerializerMethodField
()
# For easier handling on the client side, we force an id field
# this is usefull when a model has a dedicated primary key
id
=
serializers
.
SerializerMethodField
()
def
get_model_config
(
self
,
obj
=
None
):
return
self
.
Meta
.
model
.
model_config
...
...
@@ -41,6 +45,9 @@ class MyModelSerializer(MySerializerWithJSON):
return
PendingModerationSerializer
(
obj
.
pending_moderation
,
many
=
True
,
read_only
=
True
,
context
=
self
.
context
).
data
return
None
def
get_id
(
self
,
obj
):
return
obj
.
pk
class
Meta
:
model
=
MyModel
...
...
Write
Preview
Supports
Markdown
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