当前位置: 首页>>代码示例>>Python>>正文


Python ndb.IntegerProperty方法代码示例

本文整理汇总了Python中google.appengine.ext.ndb.IntegerProperty方法的典型用法代码示例。如果您正苦于以下问题:Python ndb.IntegerProperty方法的具体用法?Python ndb.IntegerProperty怎么用?Python ndb.IntegerProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.IntegerProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query_purchase_with_customer_key

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def query_purchase_with_customer_key():
    # [START purchase_with_customer_key_models]
    class Customer(ndb.Model):
        name = ndb.StringProperty()

    class Purchase(ndb.Model):
        customer = ndb.KeyProperty(kind=Customer)
        price = ndb.IntegerProperty()
    # [END purchase_with_customer_key_models]

    def query_purchases_for_customer_via_key(customer_entity):
        purchases = Purchase.query(
            Purchase.customer == customer_entity.key).fetch()
        return purchases

    return Customer, Purchase, query_purchases_for_customer_via_key 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:18,代码来源:snippets.py

示例2: query_purchase_with_ancestor_key

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def query_purchase_with_ancestor_key():
    # [START purchase_with_ancestor_key_models]
    class Customer(ndb.Model):
        name = ndb.StringProperty()

    class Purchase(ndb.Model):
        price = ndb.IntegerProperty()
    # [END purchase_with_ancestor_key_models]

    def create_purchase_for_customer_with_ancestor(customer_entity):
        purchase = Purchase(parent=customer_entity.key)
        return purchase

    def query_for_purchases_of_customer_with_ancestor(customer_entity):
        purchases = Purchase.query(ancestor=customer_entity.key).fetch()
        return purchases

    return (Customer, Purchase,
            create_purchase_for_customer_with_ancestor,
            query_for_purchases_of_customer_with_ancestor) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:22,代码来源:snippets.py

示例3: test_store_new_version_extra

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def test_store_new_version_extra(self):
    # Includes an unrelated entity in the PUT. It must be in the same entity
    # group.
    cls = monotonic.get_versioned_root_model('fidoula')
    parent = ndb.Key(cls, 'foo')
    class Unrelated(ndb.Model):
      b = ndb.IntegerProperty()
    unrelated = Unrelated(id='bar', parent=parent, b=42)
    actual = monotonic.store_new_version(
        EntityX(a=1, parent=parent), cls, extra=[unrelated])
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID), actual)
    actual = monotonic.store_new_version(EntityX(a=2, parent=parent), cls)
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID - 1), actual)
    self.assertEqual({'b': 42}, unrelated.key.get().to_dict()) 
开发者ID:luci,项目名称:luci-py,代码行数:18,代码来源:monotonic_test.py

示例4: _test_repeated_structured_properties_class

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def _test_repeated_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    class Inner(ndb.Model):
      a = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      inner = structured_cls(Inner, repeated=True)

    # Repeated structured property -> list of dicts.
    entity = Outter()
    entity.inner.extend([Inner(a=1), Inner(a=2)])
    self.assertEqual(
        {'inner': [{'a': 1}, {'a': 2}]},
        entity.to_serializable_dict())

    # Reverse also works.
    self.assertEqual(
        entity,
        Outter.from_serializable_dict({'inner': [{'a': 1}, {'a': 2}]})) 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:serializable_test.py

示例5: test_bad_type_for_repeated_property

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def test_bad_type_for_repeated_property(self):
    """Trying to deserialize repeated property not from a list -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty(repeated=True)

    # A list, tuple or nothing should work.
    Entity.from_serializable_dict({'prop': [1]})
    Entity.from_serializable_dict({'prop': (1,)})
    Entity.from_serializable_dict({})

    # A single item shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 1})
    # 'None' shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': None})
    # Dict shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': {}}) 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:serializable_test.py

示例6: test_generate_entity_schema

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def test_generate_entity_schema(self):

    class NestedTestModel(ndb.Model):
      nested_string_attribute = ndb.StringProperty()

    class TestModel(ndb.Model):
      string_attribute = ndb.StringProperty()
      integer_attribute = ndb.IntegerProperty()
      boolean_attribute = ndb.BooleanProperty()
      nested_attribute = ndb.StructuredProperty(NestedTestModel)

    schema = bigquery._generate_entity_schema(TestModel())
    expected_schema_names = _populate_schema_names(self.entity_schema)
    schema_names = _populate_schema_names(schema)
    self.assertCountEqual(expected_schema_names, schema_names) 
开发者ID:google,项目名称:loaner,代码行数:17,代码来源:bigquery_test.py

示例7: get_IntegerField

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def get_IntegerField(kwargs):
    """
    Returns an ``IntegerField``, applying the ``ndb.IntegerProperty`` range
    limits.
    """
    v = validators.NumberRange(min=-0x8000000000000000, max=0x7fffffffffffffff)
    kwargs['validators'].append(v)
    return f.IntegerField(**kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:10,代码来源:ndb.py

示例8: convert_IntegerProperty

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def convert_IntegerProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.IntegerProperty``."""
        if prop._repeated:
            return IntegerListPropertyField(**kwargs)
        return get_IntegerField(kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:ndb.py

示例9: __call__

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def __call__(cls, *args, **kwds):
        if kwds:
            #logging.info('Table called cls = %s, kwds = %s', cls, kwds)
            pass
        if cls not in cls._instances:
            cls._instances[cls] = super(Table, cls).__call__(*args, **{})
            datastore_type = {
                'text': ndb.StringProperty(),
                'list<bigint>': ndb.IntegerProperty(repeated = True),
                'list<int>': ndb.IntegerProperty(repeated = True),
                'int': ndb.IntegerProperty(),
                'ascii': ndb.StringProperty(indexed = False),
            }
            attr_list = kwds['attrs']
            attrs = {}
            for attr in attr_list:
                (name, typ) = tuple(attr.split())
                attrs[name] = copy.copy(datastore_type[typ])
            StorageProxy = type(cls.__name__, (ndb.Model,), attrs)

            setattr(cls._instances[cls], 'StorageProxy', StorageProxy)
            setattr(cls._instances[cls], 'attrs', kwds['attrs'])
            setattr(cls._instances[cls], 'p_keys', kwds['p_keys'])

            gql = "SELECT * FROM {name} WHERE {cond}"\
                .format(name = cls.__name__, cond = ' AND '.join([kwds['p_keys'][c]+'=:%d'%(c+1) for c in xrange(len(kwds['p_keys']))]))
            select = ndb.gql(gql)
            setattr(cls._instances[cls], 'select', select)

            parent_keys = kwds['p_keys'][1:]
            if parent_keys:
                gql = "SELECT * FROM {name} WHERE {cond}"\
                    .format(name = cls.__name__, cond = ' AND '.join([parent_keys[c]+'=:%d'%(c+1) for c in xrange(len(parent_keys))]))
                select_all_with_parent = ndb.gql(gql)
                setattr(cls._instances[cls], 'select_all_with_parent', select_all_with_parent)

        return cls._instances[cls] 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:39,代码来源:db_datastore.py

示例10: testIntProperty_shouldConvertToString

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def testIntProperty_shouldConvertToString(self):
        self.__assert_conversion(ndb.IntegerProperty, graphene.Int) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:4,代码来源:test_converter.py

示例11: get_versioned_root_model

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def get_versioned_root_model(model_name):
  """Returns a root model that can be used for versioned entities.

  Using this entity for get_versioned_most_recent(),
  get_versioned_most_recent_with_root() and store_new_version() is optional. Any
  entity with cls.current as an ndb.IntegerProperty will do.
  """
  assert isinstance(model_name, str), model_name
  class _Root(Root):
    @classmethod
    def _get_kind(cls):
      return model_name

  return _Root 
开发者ID:luci,项目名称:luci-py,代码行数:16,代码来源:monotonic.py

示例12: test_repeated_properties

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def test_repeated_properties(self):
    """Test that properties with repeated=True are handled."""
    class IntsEntity(ndb.Model, serializable.SerializableModelMixin):
      ints = ndb.IntegerProperty(repeated=True)
    class DatesEntity(ndb.Model, serializable.SerializableModelMixin):
      dates = ndb.DateTimeProperty(repeated=True)

    # Same point in time as datetime and as timestamp.
    dt = datetime.datetime(2012, 1, 2, 3, 4, 5)
    ts = 1325473445000000

    # Repeated properties that are not set are converted to empty lists.
    self.assertEqual({'ints': []}, IntsEntity().to_serializable_dict())
    self.assertEqual({'dates': []}, DatesEntity().to_serializable_dict())

    # List of ints works (as an example of simple repeated property).
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity(ints=[1, 2]).to_serializable_dict())
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity.convert_serializable_dict({'ints': [1, 2]}))

    # List of datetimes works (as an example of not-so-simple property).
    self.assertEqual(
        {'dates': [ts, ts]},
        DatesEntity(dates=[dt, dt]).to_serializable_dict())
    self.assertEqual(
        {'dates': [dt, dt]},
        DatesEntity.convert_serializable_dict({'dates': [ts, ts]})) 
开发者ID:luci,项目名称:luci-py,代码行数:32,代码来源:serializable_test.py

示例13: _test_structured_properties_class

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def _test_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    # Plain ndb.Model.
    class InnerSimple(ndb.Model):
      a = ndb.IntegerProperty()

    # With SerializableModelMixin.
    class InnerSmart(ndb.Model, serializable.SerializableModelMixin):
      serializable_properties = {
        'a': serializable.READABLE | serializable.WRITABLE,
      }
      a = ndb.IntegerProperty()
      b = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      simple = structured_cls(InnerSimple)
      smart = structured_cls(InnerSmart)

    # InnerSimple gets serialized entirely, while only readable fields
    # on InnerSmart are serialized.
    entity = Outter()
    entity.simple = InnerSimple(a=1)
    entity.smart = InnerSmart(a=2, b=3)
    self.assertEqual(
        {'simple': {'a': 1}, 'smart': {'a': 2}},
        entity.to_serializable_dict())

    # Works backwards as well. Note that 'convert_serializable_dict' returns
    # a dictionary that can be fed to entity's 'populate' or constructor. Entity
    # by itself is smart enough to transform subdicts into structured
    # properties.
    self.assertEqual(
        Outter(simple=InnerSimple(a=1), smart=InnerSmart(a=2)),
        Outter.from_serializable_dict({'simple': {'a': 1}, 'smart': {'a': 2}})) 
开发者ID:luci,项目名称:luci-py,代码行数:36,代码来源:serializable_test.py

示例14: test_exclude_works

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def test_exclude_works(self):
    """|exclude| argument of to_serializable_dict() is respected."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop1 = ndb.IntegerProperty()
      prop2 = ndb.IntegerProperty()
      prop3 = ndb.IntegerProperty()

    entity = Entity(prop1=1, prop2=2, prop3=3)
    self.assertEqual(
        {'prop1': 1, 'prop3': 3},
        entity.to_serializable_dict(exclude=['prop2'])) 
开发者ID:luci,项目名称:luci-py,代码行数:13,代码来源:serializable_test.py

示例15: test_from_serializable_dict_kwargs_work

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import IntegerProperty [as 别名]
def test_from_serializable_dict_kwargs_work(self):
    """Keyword arguments in from_serializable_dict are passed to constructor."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty()

    # Pass entity key via keyword parameters.
    entity = Entity.from_serializable_dict(
        {'prop': 123}, id='my id', parent=ndb.Key('Fake', 'parent'))
    self.assertEqual(123, entity.prop)
    self.assertEqual(ndb.Key('Fake', 'parent', 'Entity', 'my id'), entity.key) 
开发者ID:luci,项目名称:luci-py,代码行数:12,代码来源:serializable_test.py


注:本文中的google.appengine.ext.ndb.IntegerProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。