Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4fc467

Browse files
Promote 'many_init' to public API. Closes encode#2152.
1 parent deec61e commit f4fc467

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/api-guide/serializers.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,21 @@ Here's an example of how you might choose to implement multiple updates:
689689

690690
It is possible that a third party package may be included alongside the 3.1 release that provides some automatic support for multiple update operations, similar to the `allow_add_remove` behavior that was present in REST framework 2.
691691

692+
#### Customizing ListSerializer initialization
693+
694+
When a serializer with `many=True` is instantiated, we need to determine which arguments and keyword arguments should be passed to the `.__init__()` method for both the child `Serializer` class, and for the parent `ListSerializer` class.
695+
696+
The default implementation is to pass all arguments to both classes, except for `validators`, and any custom keyword arguments, both of which are assumed to be intended for the child serializer class.
697+
698+
Occasionally you might need to explicitly specify how the child and parent classes should be instantiated when `many=True` is passed. You can do so by using the `many_init` class method.
699+
700+
@classmethod
701+
def many_init(cls, *args, **kwargs):
702+
# Instantiate the child serializer.
703+
kwargs['child'] = cls()
704+
# Instantiate the parent list serializer.
705+
return CustomListSerializer(*args, **kwargs)
706+
692707
---
693708

694709
# BaseSerializer

0 commit comments

Comments
 (0)