diff options
| author | Tom Christie | 2013-02-12 12:14:58 +0000 | 
|---|---|---|
| committer | Tom Christie | 2013-02-12 12:14:58 +0000 | 
| commit | f642ee48a666d5cfc3a15cf8c33629bbb6173787 (patch) | |
| tree | 45ecf98886339568cc4b9d4940b8cb32a6cb06c8 | |
| parent | 112753917d7a9a1effe6e64d9344de3466425733 (diff) | |
| download | django-rest-framework-f642ee48a666d5cfc3a15cf8c33629bbb6173787.tar.bz2 | |
Document serializing querysets
| -rw-r--r-- | docs/api-guide/serializers.md | 9 | 
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 487502e9..027c343c 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -80,6 +80,15 @@ By default, serializers must be passed values for all required fields or they wi      serializer = CommentSerializer(comment, data={'content': u'foo bar'}, partial=True)  # Update `instance` with partial data +## Serializing querysets + +To serialize a queryset instead of an object instance, you should pass the `many=True` flag when instantiating the serializer. + +    queryset = Comment.objects.all() +    serializer = CommentSerializer(queryset, many=True) +    serializer.data +    # [{'email': u'leila@example.com', 'content': u'foo bar', 'created': datetime.datetime(2012, 8, 22, 16, 20, 9, 822774)}, {'email': u'jamie@example.com', 'content': u'baz', 'created': datetime.datetime(2013, 1, 12, 16, 12, 45, 104445)}] +  ## Validation  When deserializing data, you always need to call `is_valid()` before attempting to access the deserialized object.  If any validation errors occur, the `.errors` and `.non_field_errors` properties will contain the resulting error messages.  | 
