Skip to content

Commit 6de9b7c

Browse files
committed
Add note on ModelSerializer validation of both model fields and serializer fields. Refs #949
1 parent 1cfb1cf commit 6de9b7c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/api-guide/serializers.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ By default, all the model fields on the class will be mapped to corresponding se
308308

309309
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.
310310

311+
---
312+
313+
**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.
314+
315+
---
316+
311317
## Specifying which fields should be included
312318

313319
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`.

0 commit comments

Comments
 (0)