diff options
| author | Tom Christie | 2013-03-17 19:59:13 +0000 |
|---|---|---|
| committer | Tom Christie | 2013-03-17 19:59:13 +0000 |
| commit | ef0caf64d326bacdf367e002e5537b8c0d444d34 (patch) | |
| tree | 3fa9a20e77a8daca24f0783c600eca6523b9a736 /docs/api-guide/serializers.md | |
| parent | e80d3d1bdfb071a288340555cb6fe8a9bce3772d (diff) | |
| download | django-rest-framework-ef0caf64d326bacdf367e002e5537b8c0d444d34.tar.bz2 | |
Extra note on method
Diffstat (limited to 'docs/api-guide/serializers.md')
| -rw-r--r-- | docs/api-guide/serializers.md | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index e7e1670b..e8d3c1b5 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -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') 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: class CommentSerializer(serializers.Serializer): @@ -33,6 +34,13 @@ Declaring a serializer looks very similar to declaring a form: created = serializers.DateTimeField() 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: instance.title = attrs['title'] instance.content = attrs['content'] |
