Simplify conversion of int and float fields

This commit is contained in:
Itai Shirav 2016-06-30 16:17:53 +03:00
parent 4efdcda97b
commit a3bd212133

View File

@ -108,10 +108,9 @@ class DateTimeField(Field):
class BaseIntField(Field):
def to_python(self, value):
if isinstance(value, int):
return value
if isinstance(value, basestring):
try:
return int(value)
except:
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
def validate(self, value):
@ -177,10 +176,9 @@ class Int64Field(BaseIntField):
class BaseFloatField(Field):
def to_python(self, value):
if isinstance(value, float):
return value
if isinstance(value, basestring) or isinstance(value, int):
try:
return float(value)
except:
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))