MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / IntField

Class IntField

mongoengine/fields.py:328–363  ·  view source on GitHub ↗

32-bit integer field.

Source from the content-addressed store, hash-verified

326
327
328class IntField(BaseField):
329 """32-bit integer field."""
330
331 def __init__(self, min_value=None, max_value=None, **kwargs):
332 """
333 :param min_value: (optional) A min value that will be applied during validation
334 :param max_value: (optional) A max value that will be applied during validation
335 :param kwargs: Keyword arguments passed into the parent :class:`~mongoengine.BaseField`
336 """
337 self.min_value, self.max_value = min_value, max_value
338 super().__init__(**kwargs)
339
340 def to_python(self, value):
341 try:
342 value = int(value)
343 except (TypeError, ValueError):
344 pass
345 return value
346
347 def validate(self, value):
348 try:
349 value = int(value)
350 except (TypeError, ValueError):
351 self.error("%s could not be converted to int" % value)
352
353 if self.min_value is not None and value < self.min_value:
354 self.error("Integer value is too small")
355
356 if self.max_value is not None and value > self.max_value:
357 self.error("Integer value is too large")
358
359 def prepare_query_value(self, op, value):
360 if value is None:
361 return value
362
363 return super().prepare_query_value(op, int(value))
364
365
366class LongField(IntField):

Callers 15

DocClass · 0.90
PersonClass · 0.90
PersonClass · 0.90
EmployeeClass · 0.90
CityClass · 0.90
PersonClass · 0.90
DocClass · 0.90
HandleNoneFieldsClass · 0.90
CommentClass · 0.90
CategoryClass · 0.90
SimpleClass · 0.90
FooClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected