本文整理匯總了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