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
ef0caf64
Commit
ef0caf64
authored
Mar 17, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extra note on method
parent
e80d3d1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletions
+13
-1
docs/api-guide/serializers.md
+8
-0
docs/tutorial/1-serialization.md
+5
-1
No files found.
docs/api-guide/serializers.md
View file @
ef0caf64
...
@@ -25,6 +25,7 @@ Let's start by creating a simple object we can use for example purposes:
...
@@ -25,6 +25,7 @@ Let's start by creating a simple object we can use for example purposes:
comment = Comment(email='leila@example.com', content='foo bar')
comment = Comment(email='leila@example.com', content='foo bar')
We'll declare a serializer that we can use to serialize and deserialize
`Comment`
objects.
We'll declare a serializer that we can use to serialize and deserialize
`Comment`
objects.
Declaring a serializer looks very similar to declaring a form:
Declaring a serializer looks very similar to declaring a form:
class CommentSerializer(serializers.Serializer):
class CommentSerializer(serializers.Serializer):
...
@@ -33,6 +34,13 @@ Declaring a serializer looks very similar to declaring a form:
...
@@ -33,6 +34,13 @@ Declaring a serializer looks very similar to declaring a form:
created = serializers.DateTimeField()
created = serializers.DateTimeField()
def restore_object(self, attrs, instance=None):
def restore_object(self, attrs, instance=None):
"""
Given a dictionary of deserialized field values, either update
an existing model instance, or create a new model instance.
Note that if we don't define this method, then deserializing
data will simply return a dictionary of items.
"""
if instance is not None:
if instance is not None:
instance.title = attrs['title']
instance.title = attrs['title']
instance.content = attrs['content']
instance.content = attrs['content']
...
...
docs/tutorial/1-serialization.md
View file @
ef0caf64
...
@@ -126,7 +126,11 @@ The first thing we need to get started on our Web API is provide a way of serial
...
@@ -126,7 +126,11 @@ The first thing we need to get started on our Web API is provide a way of serial
def restore_object(self, attrs, instance=None):
def restore_object(self, attrs, instance=None):
"""
"""
Create or update a new snippet instance.
Create or update a new snippet instance, given a dictionary
of deserialized field values.
Note that if we don't define this method, then deserializing
data will simply return a dictionary of items.
"""
"""
if instance:
if instance:
# Update existing instance
# Update existing 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