Fix example of requires_context attribute (#8952)

This commit is contained in:
Vladimir Kasatkin 2023-05-31 07:36:21 +03:00 committed by GitHub
parent e2a4559c03
commit ff5f647df0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -295,13 +295,14 @@ To write a class-based validator, use the `__call__` method. Class-based validat
In some advanced cases you might want a validator to be passed the serializer In some advanced cases you might want a validator to be passed the serializer
field it is being used with as additional context. You can do so by setting field it is being used with as additional context. You can do so by setting
a `requires_context = True` attribute on the validator. The `__call__` method a `requires_context = True` attribute on the validator class. The `__call__` method
will then be called with the `serializer_field` will then be called with the `serializer_field`
or `serializer` as an additional argument. or `serializer` as an additional argument.
requires_context = True class MultipleOf:
requires_context = True
def __call__(self, value, serializer_field): def __call__(self, value, serializer_field):
... ...
[cite]: https://docs.djangoproject.com/en/stable/ref/validators/ [cite]: https://docs.djangoproject.com/en/stable/ref/validators/