Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
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
edx
django-rest-framework
Commits
78a741be
Commit
78a741be
authored
Nov 13, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split out .create and .update on ListSerializer
parent
fd97d9bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
rest_framework/serializers.py
+24
-11
No files found.
rest_framework/serializers.py
View file @
78a741be
...
...
@@ -449,26 +449,39 @@ class ListSerializer(BaseSerializer):
serializer
=
self
)
def
update
(
self
,
instance
,
validated_data
):
raise
NotImplementedError
(
"Serializers with many=True do not support multiple update by "
"default, only multiple create. For updates it is unclear how to "
"deal with insertions and deletions. If you need to support "
"multiple update, use a `ListSerializer` class and override "
"`.update()` so you can specify the behavior exactly."
)
def
create
(
self
,
validated_data
):
return
[
self
.
child
.
create
(
attrs
)
for
attrs
in
validated_data
]
def
save
(
self
,
**
kwargs
):
"""
Save and return a list of object instances.
"""
assert
self
.
instance
is
None
,
(
"Serializers do not support multiple update by default, only "
"multiple create. For updates it is unclear how to deal with "
"insertions and deletions. If you need to support multiple update, "
"use a `ListSerializer` class and override `.save()` so you can "
"specify the behavior exactly."
)
validated_data
=
[
dict
(
list
(
attrs
.
items
())
+
list
(
kwargs
.
items
()))
for
attrs
in
self
.
validated_data
]
self
.
instance
=
[
self
.
child
.
create
(
attrs
)
for
attrs
in
validated_data
]
if
self
.
instance
is
not
None
:
self
.
instance
=
self
.
update
(
self
.
instance
,
validated_data
)
assert
self
.
instance
is
not
None
,
(
'`update()` did not return an object instance.'
)
else
:
self
.
instance
=
self
.
create
(
validated_data
)
assert
self
.
instance
is
not
None
,
(
'`create()` did not return an object instance.'
)
return
self
.
instance
...
...
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