mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Fix example of requires_context attribute (#8952)
				
					
				
			This commit is contained in:
		
							parent
							
								
									e2a4559c03
								
							
						
					
					
						commit
						ff5f647df0
					
				| 
						 | 
				
			
			@ -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/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user