Loading django/db/models/fields/__init__.py +0 −6 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import collections import copy import datetime import decimal import math import uuid import warnings from base64 import b64decode, b64encode Loading Loading @@ -1875,11 +1874,6 @@ class IntegerField(Field): return None return int(value) def get_prep_lookup(self, lookup_type, value): if lookup_type in ('gte', 'lt') and isinstance(value, float): value = math.ceil(value) return super(IntegerField, self).get_prep_lookup(lookup_type, value) def get_internal_type(self): return "IntegerField" Loading django/db/models/lookups.py +22 −0 Original line number Diff line number Diff line import math import warnings from copy import copy Loading Loading @@ -201,6 +202,27 @@ class LessThanOrEqual(BuiltinLookup): Field.register_lookup(LessThanOrEqual) class IntegerFieldFloatRounding(object): """ Allow floats to work as query values for IntegerField. Without this, the decimal portion of the float would always be discarded. """ def get_prep_lookup(self): if isinstance(self.rhs, float): self.rhs = math.ceil(self.rhs) return super(IntegerFieldFloatRounding, self).get_prep_lookup() class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual): pass IntegerField.register_lookup(IntegerGreaterThanOrEqual) class IntegerLessThan(IntegerFieldFloatRounding, LessThan): pass IntegerField.register_lookup(IntegerLessThan) class In(BuiltinLookup): lookup_name = 'in' Loading Loading
django/db/models/fields/__init__.py +0 −6 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ import collections import copy import datetime import decimal import math import uuid import warnings from base64 import b64decode, b64encode Loading Loading @@ -1875,11 +1874,6 @@ class IntegerField(Field): return None return int(value) def get_prep_lookup(self, lookup_type, value): if lookup_type in ('gte', 'lt') and isinstance(value, float): value = math.ceil(value) return super(IntegerField, self).get_prep_lookup(lookup_type, value) def get_internal_type(self): return "IntegerField" Loading
django/db/models/lookups.py +22 −0 Original line number Diff line number Diff line import math import warnings from copy import copy Loading Loading @@ -201,6 +202,27 @@ class LessThanOrEqual(BuiltinLookup): Field.register_lookup(LessThanOrEqual) class IntegerFieldFloatRounding(object): """ Allow floats to work as query values for IntegerField. Without this, the decimal portion of the float would always be discarded. """ def get_prep_lookup(self): if isinstance(self.rhs, float): self.rhs = math.ceil(self.rhs) return super(IntegerFieldFloatRounding, self).get_prep_lookup() class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual): pass IntegerField.register_lookup(IntegerGreaterThanOrEqual) class IntegerLessThan(IntegerFieldFloatRounding, LessThan): pass IntegerField.register_lookup(IntegerLessThan) class In(BuiltinLookup): lookup_name = 'in' Loading