本文整理匯總了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
示例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)
示例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())
示例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}]}))
示例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': {}})
示例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)
示例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)
示例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)
示例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]
示例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)
示例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
示例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]}))
示例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}}))
示例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']))
示例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)