本文整理汇总了Python中google.appengine.ext.db.ReferenceProperty方法的典型用法代码示例。如果您正苦于以下问题:Python db.ReferenceProperty方法的具体用法?Python db.ReferenceProperty怎么用?Python db.ReferenceProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.ext.db
的用法示例。
在下文中一共展示了db.ReferenceProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _decode_bookmark
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import ReferenceProperty [as 别名]
def _decode_bookmark(self, bookmark):
"""Decodes a bookmark and prepares the values to be used on queries.
Currently supported properties are DateTimeProperty, FloatProperty,
IntegerProperty, StringProperty and ReferenceProperty.
Returns:
A dictionary of property names/values to be used in queries.
"""
required = list(self._bookmark_properties)
required.append('_')
try:
bookmark = decode_bookmark(bookmark)
# Ensure that all required values are available.
for key in required:
if key not in bookmark:
return None
except:
return None
for key in required:
value = bookmark[key]
if key == '_':
self._first_result = bookmark[key]
elif key == '__key__':
bookmark[key] = db.Key(value)
else:
prop = getattr(self._model_class, key)
if isinstance(prop, db.ReferenceProperty):
bookmark[key] = db.Key(value)
elif isinstance(prop, db.DateTimeProperty):
bookmark[key] = parseDateTime(value)
else:
bookmark[key] = prop.data_type(value)
return bookmark
# from http://kbyanc.blogspot.com/2007/09/python-reconstructing-datetimes-from.html
示例2: convert_ReferenceProperty
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import ReferenceProperty [as 别名]
def convert_ReferenceProperty(model, prop, kwargs):
"""Returns a form field for a ``db.ReferenceProperty``."""
kwargs['reference_class'] = prop.reference_class
kwargs.setdefault('allow_blank', not prop.required)
return ReferencePropertyField(**kwargs)
示例3: __new__
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import ReferenceProperty [as 别名]
def __new__(cls, name, bases, dct):
myname = name.replace('ConnectionModel','').lower()
if myname:
#this is not the baseclass
to_collection_name = 'myto_%s_connections' % myname #or any other naming scheme you like
from_collection_name = 'myfrom_%s_connections' % myname #or any other naming scheme you like
myto = 'myto_%s'%myname
myfrom = 'myfrom_%s'%myname
dct[myto] = db.ReferenceProperty(collection_name = to_collection_name)
dct[myfrom] = db.ReferenceProperty(collection_name = from_collection_name)
if 'put' in dct:
myput = dct['put']
else:
myput = None
def put(self):
setattr(self, myto, self.myto)
setattr(self, myfrom, self.myfrom)
self._validate_connected_types()
if myput is not None:
myput(self)
else:
MyClass = eval(name)
super(MyClass, self).put()
dct['put'] = put
return super(ConnectionModelMetaclass, cls).__new__(cls, name, bases, dct)
示例4: get_form_field
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import ReferenceProperty [as 别名]
def get_form_field(self, **kwargs):
"""Return a Django form field appropriate for a reference property.
This defaults to a ModelChoiceField instance.
"""
defaults = {'form_class': ModelChoiceField,
'reference_class': self.reference_class}
defaults.update(kwargs)
return super(ReferenceProperty, self).get_form_field(**defaults)
示例5: get_value_for_form
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import ReferenceProperty [as 别名]
def get_value_for_form(self, instance):
"""Extract the property value from the instance for use in a form.
This return the key object for the referenced object, or None.
"""
value = super(ReferenceProperty, self).get_value_for_form(instance)
if value is not None:
value = value.key()
return value