當前位置: 首頁>>代碼示例>>Python>>正文


Python peewee.CompositeKey方法代碼示例

本文整理匯總了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 
開發者ID:05bit,項目名稱:peewee-async,代碼行數:42,代碼來源:peewee_async.py

示例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() 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:10,代碼來源:test.py


注:本文中的peewee.CompositeKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。