mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-20 05:23:18 +03:00
Document serializing querysets
This commit is contained in:
parent
112753917d
commit
f642ee48a6
|
@ -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
|
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
|
## 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.
|
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.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user