From cd09f2b9eec1e76766798b0878c86a3e8548ddef Mon Sep 17 00:00:00 2001 From: Petros Moisiadis Date: Fri, 13 May 2016 17:28:02 +0300 Subject: [PATCH] Document allow_empty argument ListSerializer fields or serializers that are passed many=True may also take an allow_empty=False argument to disallow empty lists as valid input. Information about this was part of the 3.2 release announcement, but had not been part of the API docs until now. --- docs/api-guide/serializers.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 78d43a535..bc79406d7 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -731,9 +731,17 @@ The `ListSerializer` class provides the behavior for serializing and validating When a serializer is instantiated and `many=True` is passed, a `ListSerializer` instance will be created. The serializer class then becomes a child of the parent `ListSerializer` +The following argument can also be passed to a `ListSerializer` field or a serializer that is passed `many=True`: + +### `allow_empty` + +This is `True` by default, but can be set to `False` if you want to disallow empty lists as valid input. + +### Customizing `ListSerializer` behavior + There *are* a few use cases when you might want to customize the `ListSerializer` behavior. For example: -* You want to provide particular validation of the lists, such as always ensuring that there is at least one element in a list. +* You want to provide particular validation of the lists, such as checking that one element does not conflict with another element in a list. * You want to customize the create or update behavior of multiple objects. For these cases you can modify the class that is used when `many=True` is passed, by using the `list_serializer_class` option on the serializer `Meta` class.