From ff5f647df01d83f1bad32e37ed8d9181da21538c Mon Sep 17 00:00:00 2001 From: Vladimir Kasatkin Date: Wed, 31 May 2023 07:36:21 +0300 Subject: [PATCH] Fix example of `requires_context` attribute (#8952) --- docs/api-guide/validators.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/api-guide/validators.md b/docs/api-guide/validators.md index dac937d9b..2a1e3e6b3 100644 --- a/docs/api-guide/validators.md +++ b/docs/api-guide/validators.md @@ -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 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` 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/