From 48bfcc9bcf0b7c66168ed6f1df089e64f5e6f49a Mon Sep 17 00:00:00 2001 From: Vladimir Kasatkin Date: Tue, 18 Apr 2023 12:32:02 +0300 Subject: [PATCH] Fix example of `requires_context` attribute --- 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/