本文整理汇总了Python中peewee.CompositeKey方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.CompositeKey方法的具体用法?Python peewee.CompositeKey怎么用?Python peewee.CompositeKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.CompositeKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_object
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CompositeKey [as 别名]
def update_object(obj, only=None):
"""Update object asynchronously.
:param obj: object to update
:param only: list or tuple of fields to updata, is `None` then all fields
updated
This function does the same as `Model.save()`_ for already saved object,
but it doesn't invoke ``save()`` method on model class. That is
important to know if you overrided save method for your model.
.. _Model.save(): http://peewee.readthedocs.io/en/latest/peewee/
api.html#Model.save
"""
# Here are private calls involved:
#
# - obj._data
# - obj._meta
# - obj._prune_fields()
# - obj._pk_expr()
# - obj._dirty.clear()
#
warnings.warn("update_object() is deprecated, Manager.update() "
"should be used instead",
DeprecationWarning)
field_dict = dict(obj.__data__)
pk_field = obj._meta.primary_key
if only:
field_dict = obj._prune_fields(field_dict, only)
if not isinstance(pk_field, peewee.CompositeKey):
field_dict.pop(pk_field.name, None)
else:
field_dict = obj._prune_fields(field_dict, obj.dirty_fields)
rows = await update(obj.update(**field_dict).where(obj._pk_expr()))
obj._dirty.clear()
return rows
示例2: test_composite_key_no_change
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CompositeKey [as 别名]
def test_composite_key_no_change(self):
class SomeModel(pw.Model):
x = pw.IntegerField()
y = pw.IntegerField()
class Meta:
primary_key = pw.CompositeKey('x', 'y')
database = self.db
self.evolve_and_check_noop()