Example #1
0
    def __init__(self, field_type=None, field_name=None):
        """
        Construct a new field

        :param field_type: type which field would store. If set to None it could
            store any type.

        :param field_name: name of field in mongo document. If set to None it
            would be the same as field name. Any two field in one model can't
            have the same `field_name`.
        """
        if field_type is not None and not isinstance(field_type, basestring) and \
           not check_mongo_type(field_type):
            raise TypeError("Invalid mongo type %(type)s" % {'type': type_name(field_type)})

        self._field_type = field_type
        self._field_name = field_name
Example #2
0
    def __init__(self, field_type=None, field_name=None):
        """
        Construct a new field

        :param field_type: type which field would store. If set to None it could
            store any type.

        :param field_name: name of field in mongo document. If set to None it
            would be the same as field name. Any two field in one model can't
            have the same `field_name`.
        """
        if field_type is not None and not isinstance(field_type, basestring) and \
           not check_mongo_type(field_type):
            raise TypeError("Invalid mongo type %(type)s" %
                            {'type': type_name(field_type)})

        self._field_type = field_type
        self._field_name = field_name
Example #3
0
 def test_check_mongo_type(self):
     stdTypes = (ObjectId, int, float, basestring, list, dict, datetime)
     for tp in stdTypes:
         self.assertTrue(utils.check_mongo_type(tp))