diff options
| author | Tom Christie | 2014-09-22 13:57:45 +0100 |
|---|---|---|
| committer | Tom Christie | 2014-09-22 13:57:45 +0100 |
| commit | c54f394904c3f93211b8aa073de4e9e50110f831 (patch) | |
| tree | 254fa408d0cd14c45cceeaa86116d2bb123df84b /rest_framework/compat.py | |
| parent | afb3f8ab0ad6c33b147292e9777ba0ddf3871d14 (diff) | |
| download | django-rest-framework-c54f394904c3f93211b8aa073de4e9e50110f831.tar.bz2 | |
Ensure 'messages' in fields are respected in preference to default validator messages
Diffstat (limited to 'rest_framework/compat.py')
| -rw-r--r-- | rest_framework/compat.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 7c05bed9..2b4ddb02 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -121,6 +121,25 @@ else: return [m.upper() for m in self.http_method_names if hasattr(self, m)] + +# MinValueValidator and MaxValueValidator only accept `message` in 1.8+ +if django.VERSION >= (1, 8): + from django.core.validators import MinValueValidator, MaxValueValidator +else: + from django.core.validators import MinValueValidator as DjangoMinValueValidator + from django.core.validators import MaxValueValidator as DjangoMaxValueValidator + + class MinValueValidator(DjangoMinValueValidator): + def __init__(self, *args, **kwargs): + self.message = kwargs.pop('message', self.message) + super(MinValueValidator, self).__init__(*args, **kwargs) + + class MaxValueValidator(DjangoMaxValueValidator): + def __init__(self, *args, **kwargs): + self.message = kwargs.pop('message', self.message) + super(MaxValueValidator, self).__init__(*args, **kwargs) + + # PATCH method is not implemented by Django if 'patch' not in View.http_method_names: View.http_method_names = View.http_method_names + ['patch'] |
