mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-11 04:34:25 +03:00
Merge branch 'master' of github.com:tomchristie/django-rest-framework
This commit is contained in:
commit
a67eed1466
|
@ -51,7 +51,7 @@ Defaults to `False`
|
|||
|
||||
If set, this gives the default value that will be used for the field if no input value is supplied. If not set the default behavior is to not populate the attribute at all.
|
||||
|
||||
May be set to a function or other callable, in which case the value will be evaluated each time it is used.
|
||||
May be set to a function or other callable, in which case the value will be evaluated each time it is used. When called, it will receive no arguments. If the callable has a `set_context` method, that will be called each time before getting the value with the field instance as only argument. This works the same way as for [validators](validators.md#using-set_context).
|
||||
|
||||
Note that setting a `default` value implies that the field is not required. Including both the `default` and `required` keyword arguments is invalid and will raise an error.
|
||||
|
||||
|
|
|
@ -189,6 +189,12 @@ Your `validate_<field_name>` methods should return the validated value or raise
|
|||
raise serializers.ValidationError("Blog post is not about Django")
|
||||
return value
|
||||
|
||||
---
|
||||
|
||||
**Note:** If your `<field_name>` is declared on your serializer with the parameter `required=False` then this validation step will not take place if the field is not included.
|
||||
|
||||
---
|
||||
|
||||
#### Object-level validation
|
||||
|
||||
To do any other validation that requires access to multiple fields, add a method called `.validate()` to your `Serializer` subclass. This method takes a single argument, which is a dictionary of field values. It should raise a `ValidationError` if necessary, or just return the validated values. For example:
|
||||
|
|
|
@ -148,7 +148,7 @@ For example, given the following views...
|
|||
throttle_scope = 'contacts'
|
||||
...
|
||||
|
||||
class ContactDetailView(ApiView):
|
||||
class ContactDetailView(APIView):
|
||||
throttle_scope = 'contacts'
|
||||
...
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user