@@ -231,7 +231,7 @@ py.test
231231New-Style Serializers
232232================
233233
234- In 2020 , an enhanced set of mixins were added that permit fine-grained control of nested
234+ In 2021 , an enhanced set of mixins were added that permit fine-grained control of nested
235235Serializer behavior using a ` match_on ` argument. New-style serializers delegate control
236236of the Create/Update behavior to the nested Serializer. The parent Serializer need only
237237resolve nested serializers in the right order; this is handled by the ` RelatedSaveMixin ` .
@@ -253,6 +253,33 @@ The new-style Serializers may be used as top-level Serializers to provide get-or
253253behaviors to DRF endpoints. Examples of use can be found in
254254` test_nested_serializer_mixins.py ` .
255255
256+ Migration
257+ ---------
258+
259+ To convert an existing serializer to the new style serializers, the following procedure
260+ is recommended:
261+
262+ 1 . Convert nested serializers by replacing ` serializers.ModelSerializer ` with
263+ ` UpdateOrCreateNestedSerializerMixin, serializers.ModelSerializer ` which preserves
264+ backwards-compatible behavior.
265+ 1 . Convert parent serializer by replacing ` WritableNestedModelSerializer ` with
266+ ` RelatedSaveMixin, serializers.ModelSerializer ` .
267+ 1 . Verify that your test cases still pass.
268+ 1 . Modify serializers (and test case) based on desired new-style behavior e.g. by
269+ adding an explicit ` match_on ` or switching to ` GetOrCreateNestedSerializerMixin `
270+ behavior.
271+
272+ All test cases were duplicated for new-style serializers so you can see examples of
273+ converted serializers in ` tests/serializers.py ` . For example ` TeamSerializer ` and
274+ ` UserSerializer ` become ` NewTeamSerializer ` and ` NewUserSerializer ` . Examples of
275+ ` DEFAULT_MATCH_ON ` can be found in ` tests/serializers.py ` . One example of an explicit
276+ specified ` match_on ` is present, but non-default ` match_on ` values are not found in
277+ ` tests ` because they were not required to produce existing behaviors.
278+
279+ NOTE: While ` RelatedSaveMixin ` is the backwards-compatible mixin for the top-level
280+ class, it is also possible to use other mixins to get complex matching behavior without
281+ modifying the view.
282+
256283Known problems with solutions
257284=============================
258285
0 commit comments