3434from rest_framework import ISO_8601
3535from rest_framework .compat import (
3636 MaxLengthValidator , MaxValueValidator , MinLengthValidator ,
37- MinValueValidator , unicode_repr , unicode_to_repr
37+ MinValueValidator , ProhibitNullCharactersValidator , unicode_repr ,
38+ unicode_to_repr
3839)
3940from rest_framework .exceptions import ErrorDetail , ValidationError
4041from rest_framework .settings import api_settings
@@ -755,7 +756,7 @@ class CharField(Field):
755756 'invalid' : _ ('Not a valid string.' ),
756757 'blank' : _ ('This field may not be blank.' ),
757758 'max_length' : _ ('Ensure this field has no more than {max_length} characters.' ),
758- 'min_length' : _ ('Ensure this field has at least {min_length} characters.' )
759+ 'min_length' : _ ('Ensure this field has at least {min_length} characters.' ),
759760 }
760761 initial = ''
761762
@@ -778,6 +779,10 @@ def __init__(self, **kwargs):
778779 self .validators .append (
779780 MinLengthValidator (self .min_length , message = message ))
780781
782+ # ProhibitNullCharactersValidator is None on Django < 2.0
783+ if ProhibitNullCharactersValidator is not None :
784+ self .validators .append (ProhibitNullCharactersValidator ())
785+
781786 def run_validation (self , data = empty ):
782787 # Test for the empty string here so that it does not get validated,
783788 # and so that subclasses do not need to handle it explicitly
0 commit comments