本文整理汇总了Python中sqlalchemy.orm.synonym函数的典型用法代码示例。如果您正苦于以下问题:Python synonym函数的具体用法?Python synonym怎么用?Python synonym使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了synonym函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_evaluate_double_synonym_attr
def test_evaluate_double_synonym_attr(self):
class Foo(object):
pass
mapper(Foo, self.tables.users, properties={
'uname': synonym("name"),
'ufoo': synonym('uname')
})
s = Session()
jill = s.query(Foo).get(3)
s.query(Foo).update(
{Foo.ufoo: 'moonbeam'},
synchronize_session='evaluate')
eq_(jill.ufoo, 'moonbeam')
示例2: MongoReference
def MongoReference(field, ref_cls, queryset=None):
"""
Reference to a MongoDB document.
The value is cached until an assignment is made.
To use a custom queryset (instead of the default `ref_cls.objects`),
pass it as the `queryset` kwarg.
"""
if queryset is None:
queryset = ref_cls.objects
def _get(obj):
if not hasattr(obj, '_%s__cache' % field):
ref_id = getattr(obj, field)
if ref_id is None:
ref = None
else:
ref = queryset.get(pk=ref_id)
setattr(obj, '_%s__cache' % field, ref)
return getattr(obj, '_%s__cache' % field)
def _set(obj, val):
if hasattr(obj, '_%s__cache' % field):
delattr(obj, '_%s__cache' % field)
if isinstance(val, ref_cls):
val = val.pk
if isinstance(val, ObjectId):
val = str(val)
setattr(obj, field, val)
return synonym(field, descriptor=property(_get, _set))
示例3: setup_orm
def setup_orm():
tables = meta.metadata.tables
columns = tables['group_mailing_list_messages'].c
orm.mapper(GroupMailingListMessage,
tables['group_mailing_list_messages'],
inherits=ContentItem,
polymorphic_identity='mailing_list_message',
polymorphic_on=tables['content_items'].c.content_type,
properties = {
'reply_to': relation(GroupMailingListMessage,
backref=backref('replies'),
foreign_keys=(columns.reply_to_message_machine_id),
primaryjoin=columns.id == columns.reply_to_message_machine_id,
remote_side=(columns.id)),
'thread': relation(GroupMailingListMessage,
post_update=True,
order_by=[asc(columns.sent)],
backref=backref('posts'),
foreign_keys=(columns.thread_message_machine_id),
primaryjoin=columns.id == columns.thread_message_machine_id,
remote_side=(columns.id)),
'author': relation(User,
backref=backref('messages')),
'group': relation(Group,
primaryjoin=(columns.group_id == tables['groups'].c.id)),
'attachments': synonym("files")
})
示例4: test_synonym_comparable
def test_synonym_comparable(self):
users = self.tables.users
class User(object):
class Comparator(PropComparator):
pass
def _getValue(self):
return self._value
def _setValue(self, value):
setattr(self, "_value", value)
value = property(_getValue, _setValue)
mapper(
User, users, properties={"uid": synonym("id"), "foobar": comparable_property(User.Comparator, User.value)}
)
sess = create_session()
u = User()
u.name = "ed"
sess.add(u)
sess.flush()
sess.expunge(u)
sess.merge(u)
示例5: _set_password
def _set_password(self, password):
if password:
self._password = generate_password_hash(password)
password_descriptor = property(self._get_password,
self._set_password)
password = synonym('_password',
descriptor=password_descriptor)
示例6: _get_password
def _get_password(self):
return self._password
def _set_password(self, password):
self._password = hash_password(password)
password = property(_get_password, _set_password)
password = synonym('_password', descriptor=password)
def __init__(self, username, password, name, email):
self.username = username
self.name = name
self.email = email
self.password = password
@classmethod
def get_by_username(cls, username):
return DBSession.query(cls).filter(cls.username == username).first()
@classmethod
def check_password(cls, username, password):
user = cls.get_by_username(username)
if not user:
return False
return crypt.check(user.password, password)
示例7: test_synonym_comparable
def test_synonym_comparable(self):
users = self.tables.users
class User(object):
class Comparator(PropComparator):
pass
def _getValue(self):
return self._value
def _setValue(self, value):
setattr(self, '_value', value)
value = property(_getValue, _setValue)
mapper(User, users, properties={
'uid':synonym('id'),
'foobar':comparable_property(User.Comparator,User.value),
})
sess = create_session()
u = User()
u.name = 'ed'
sess.add(u)
sess.flush()
sess.expunge(u)
sess.merge(u)
示例8: test_evaluate_double_synonym_attr
def test_evaluate_double_synonym_attr(self):
class Foo(object):
pass
mapper(
Foo,
self.tables.users,
properties={"uname": synonym("name"), "ufoo": synonym("uname")},
)
s = Session()
jill = s.query(Foo).get(3)
s.query(Foo).update(
{Foo.ufoo: "moonbeam"}, synchronize_session="evaluate"
)
eq_(jill.ufoo, "moonbeam")
示例9: start
def start(cls):
return synonym(
"_start",
descriptor=property(
cls._start_getter,
cls._start_setter,
)
)
示例10: end
def end(cls):
return synonym(
"_end",
descriptor=property(
cls._end_getter,
cls._end_setter
)
)
示例11: json_synonym
def json_synonym(name):
"""Use json to serialize python objects for db storage."""
def getter(self):
return json.loads(getattr(self, name), decode_datetime=True)
def setter(self, entry):
setattr(self, name, unicode(json.dumps(entry, encode_datetime=True)))
return synonym(name, descriptor=property(getter, setter))
示例12: status
def status(cls):
def get_status(self):
return self._status
def set_status(self, value):
if self._status != value:
self._status = value
signal_execution_status_change.send(self)
return synonym('_status', descriptor=property(get_status, set_status))
示例13: test_synonym_group_bug
def test_synonym_group_bug(self):
orders, Order = self.tables.orders, self.classes.Order
mapper(Order, orders, properties={
'isopen':synonym('_isopen', map_column=True),
'description':deferred(orders.c.description, group='foo')
})
sess = create_session()
o1 = sess.query(Order).get(1)
eq_(o1.description, "order 1")
示例14: target_entity_type
def target_entity_type(cls):
return synonym(
"_target_entity_type",
descriptor=property(
fget=cls._target_entity_type_getter,
doc="""The entity type which this object is valid for.
Usually it is set to the TargetClass directly.
"""
)
)
示例15: test_evaluate_synonym_string
def test_evaluate_synonym_string(self):
class Foo(object):
pass
mapper(Foo, self.tables.users, properties={"uname": synonym("name")})
s = Session()
jill = s.query(Foo).get(3)
s.query(Foo).update(
{"uname": "moonbeam"}, synchronize_session="evaluate"
)
eq_(jill.uname, "moonbeam")