Skip to content

Commit 0773c99

Browse files
committed
Simplify LongField implementation
1 parent 703cd49 commit 0773c99

File tree

1 file changed

+1
-35
lines changed

1 file changed

+1
-35
lines changed

mongoengine/fields.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -356,46 +356,12 @@ def prepare_query_value(self, op, value):
356356
return super().prepare_query_value(op, int(value))
357357

358358

359-
class LongField(BaseField):
359+
class LongField(IntField):
360360
"""64-bit integer field. (Equivalent to IntField since the support to Python2 was dropped)"""
361361

362-
def __init__(self, min_value=None, max_value=None, **kwargs):
363-
"""
364-
:param min_value: (optional) A min value that will be applied during validation
365-
:param max_value: (optional) A max value that will be applied during validation
366-
:param kwargs: Keyword arguments passed into the parent :class:`~mongoengine.BaseField`
367-
"""
368-
self.min_value, self.max_value = min_value, max_value
369-
super().__init__(**kwargs)
370-
371-
def to_python(self, value):
372-
try:
373-
value = int(value)
374-
except (TypeError, ValueError):
375-
pass
376-
return value
377-
378362
def to_mongo(self, value):
379363
return Int64(value)
380364

381-
def validate(self, value):
382-
try:
383-
value = int(value)
384-
except (TypeError, ValueError):
385-
self.error("%s could not be converted to long" % value)
386-
387-
if self.min_value is not None and value < self.min_value:
388-
self.error("Long value is too small")
389-
390-
if self.max_value is not None and value > self.max_value:
391-
self.error("Long value is too large")
392-
393-
def prepare_query_value(self, op, value):
394-
if value is None:
395-
return value
396-
397-
return super().prepare_query_value(op, int(value))
398-
399365

400366
class FloatField(BaseField):
401367
"""Floating point number field."""

0 commit comments

Comments
 (0)