summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/validators.py
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2015-01-10 16:14:20 +0000
committerMarc Tamlyn <marc.tamlyn@gmail.com>2015-01-10 16:18:19 +0000
commit48ad288679a0cb2e2cfb17f128903e6c5b1c4870 (patch)
tree75bacb810dbe071058b5c5cf7d8dcb8e20f3f500 /django/contrib/postgres/validators.py
parent916e38802f151b34aaca487dc7e928946e81be73 (diff)
downloaddjango-48ad288679a0cb2e2cfb17f128903e6c5b1c4870.tar.gz
Fixed #24001 -- Added range fields for PostgreSQL.
Added support for PostgreSQL range types to contrib.postgres. - 5 new model fields - 4 new form fields - New validators - Uses psycopg2's range type implementation in python
Diffstat (limited to 'django/contrib/postgres/validators.py')
-rw-r--r--django/contrib/postgres/validators.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/django/contrib/postgres/validators.py b/django/contrib/postgres/validators.py
index 19d0a69765..49ec921db1 100644
--- a/django/contrib/postgres/validators.py
+++ b/django/contrib/postgres/validators.py
@@ -1,7 +1,10 @@
import copy
from django.core.exceptions import ValidationError
-from django.core.validators import MaxLengthValidator, MinLengthValidator
+from django.core.validators import (
+ MaxLengthValidator, MinLengthValidator, MaxValueValidator,
+ MinValueValidator,
+)
from django.utils.deconstruct import deconstructible
from django.utils.translation import ungettext_lazy, ugettext_lazy as _
@@ -63,3 +66,13 @@ class KeysValidator(object):
def __ne__(self, other):
return not (self == other)
+
+
+class RangeMaxValueValidator(MaxValueValidator):
+ compare = lambda self, a, b: a.upper > b
+ message = _('Ensure that this range is completely less than or equal to %(limit_value)s.')
+
+
+class RangeMinValueValidator(MinValueValidator):
+ compare = lambda self, a, b: a.lower < b
+ message = _('Ensure that this range is completely greater than or equal to %(limit_value)s.')