mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-19 13:03:19 +03:00
Initial link from Serializers to Validators
This commit is contained in:
parent
b8f396bce8
commit
71e1a3942e
|
@ -505,6 +505,19 @@ This option should be a list or tuple of field names, and is declared as follows
|
||||||
|
|
||||||
Model fields which have `editable=False` set, and `AutoField` fields will be set to read-only by default, and do not need to be added to the `read_only_fields` option.
|
Model fields which have `editable=False` set, and `AutoField` fields will be set to read-only by default, and do not need to be added to the `read_only_fields` option.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Note**: There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. Here you **must** specify the field explicitly and provide a valid default value.
|
||||||
|
|
||||||
|
A common example of this is a read-only relation to currently authenticated `User` which is `unique_together` with another identifier. In this case you would declare the user field like so:
|
||||||
|
|
||||||
|
user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
|
||||||
|
|
||||||
|
Please review the [Validators Documentation](/api-guide/validators/) for details on the [UniqueTogetherValidator](/api-guide/validators/#uniquetogethervalidator) and [CurrentUserDefault](/api-guide/validators/#currentuserdefault) classes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
## Specifying additional keyword arguments for fields.
|
## Specifying additional keyword arguments for fields.
|
||||||
|
|
||||||
There is also a shortcut allowing you to specify arbitrary additional keyword arguments on fields, using the `extra_kwargs` option. Similarly to `read_only_fields` this means you do not need to explicitly declare the field on the serializer.
|
There is also a shortcut allowing you to specify arbitrary additional keyword arguments on fields, using the `extra_kwargs` option. Similarly to `read_only_fields` this means you do not need to explicitly declare the field on the serializer.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user