diff options
| author | Tom Christie | 2012-11-09 09:04:45 -0800 |
|---|---|---|
| committer | Tom Christie | 2012-11-09 09:04:45 -0800 |
| commit | da1aa5542cff3295d3a53821d4afe02911094181 (patch) | |
| tree | d40beff70dbc341d0a0b1bc38636a912276d2899 /docs/api-guide/serializers.md | |
| parent | b1b284cdbc7732b8825565cf70f8cc56f56971fc (diff) | |
| parent | e224061189a6a5ea2c063f3820239eed6c3a88fb (diff) | |
| download | django-rest-framework-da1aa5542cff3295d3a53821d4afe02911094181.tar.bz2 | |
Merge pull request #394 from tomchristie/read_only_fields
Read only fields
Diffstat (limited to 'docs/api-guide/serializers.md')
| -rw-r--r-- | docs/api-guide/serializers.md | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 0cdae1ce..a9589144 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -248,6 +248,15 @@ The default `ModelSerializer` uses primary keys for relationships, but you can a The `depth` option should be set to an integer value that indicates the depth of relationships that should be traversed before reverting to a flat representation. +## Specifying which fields should be read-only + +You may wish to specify multiple fields as read-only. Instead of adding each field explicitely with the `read_only=True` attribute, you may use the `read_only_fields` Meta option, like so: + + class AccountSerializer(serializers.ModelSerializer): + class Meta: + model = Account + read_only_fields = ('created', 'modified') + ## Customising the default fields You can create customized subclasses of `ModelSerializer` that use a different set of default fields for the representation, by overriding various `get_<field_type>_field` methods. |
