diff options
| author | Tom Christie | 2013-07-11 21:02:47 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-07-11 21:02:47 +0100 |
| commit | 6de9b7c8caaea00df2b1399ecd7b815ac556a70e (patch) | |
| tree | e395c5e87a6c45fa2a770230cc748f3c12f46fa5 /docs/api-guide/serializers.md | |
| parent | 1cfb1cf45861e7dd20b5ef3eecb6c0402e15a82f (diff) | |
| download | django-rest-framework-6de9b7c8caaea00df2b1399ecd7b815ac556a70e.tar.bz2 | |
Add note on ModelSerializer validation of both model fields and serializer fields. Refs #949
Diffstat (limited to 'docs/api-guide/serializers.md')
| -rw-r--r-- | docs/api-guide/serializers.md | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 8e9de10e..a1f0853e 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -308,6 +308,12 @@ By default, all the model fields on the class will be mapped to corresponding se Any relationships such as foreign keys on the model will be mapped to `PrimaryKeyRelatedField`. Other models fields will be mapped to a corresponding serializer field. +--- + +**Note**: When validation is applied to a `ModelSerializer`, both the serializer fields, and their corresponding model fields must correctly validate. If you have optional fields on your model, make sure to correctly set `blank=True` on the model field, as well as setting `required=False` on the serializer field. + +--- + ## Specifying which fields should be included If you only want a subset of the default fields to be used in a model serializer, you can do so using `fields` or `exclude` options, just as you would with a `ModelForm`. |
