当前位置: 首页>>代码示例>>Python>>正文


Python apps.lazy_model_operation方法代码示例

本文整理汇总了Python中django.apps.apps.lazy_model_operation方法的典型用法代码示例。如果您正苦于以下问题:Python apps.lazy_model_operation方法的具体用法?Python apps.lazy_model_operation怎么用?Python apps.lazy_model_operation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.apps.apps的用法示例。


在下文中一共展示了apps.lazy_model_operation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: lazy_related_operation

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import lazy_model_operation [as 别名]
def lazy_related_operation(function, model, *related_models, **kwargs):
    """
    Schedule `function` to be called once `model` and all `related_models`
    have been imported and registered with the app registry. `function` will
    be called with the newly-loaded model classes as its positional arguments,
    plus any optional keyword arguments.

    The `model` argument must be a model class. Each subsequent positional
    argument is another model, or a reference to another model - see
    `resolve_relation()` for the various forms these may take. Any relative
    references will be resolved relative to `model`.

    This is a convenience wrapper for `Apps.lazy_model_operation` - the app
    registry model used is the one found in `model._meta.apps`.
    """
    models = [model] + [resolve_relation(model, rel) for rel in related_models]
    model_keys = (make_model_tuple(m) for m in models)
    apps = model._meta.apps
    return apps.lazy_model_operation(partial(function, **kwargs), *model_keys) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:21,代码来源:related.py

示例2: add_lazy_relation

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import lazy_model_operation [as 别名]
def add_lazy_relation(cls, field, relation, operation):
    warnings.warn(
        "add_lazy_relation() has been superseded by lazy_related_operation() "
        "and related methods on the Apps class.",
        RemovedInDjango20Warning, stacklevel=2)
    # Rearrange args for new Apps.lazy_model_operation

    def function(local, related, field):
        return operation(field, related, local)

    lazy_related_operation(function, cls, relation, field=field) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:13,代码来源:related.py

示例3: add_lazy_relation

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import lazy_model_operation [as 别名]
def add_lazy_relation(cls, field, relation, operation):
    warnings.warn(
        "add_lazy_relation() has been superseded by lazy_related_operation() "
        "and related methods on the Apps class.",
        RemovedInDjango20Warning, stacklevel=2)
    # Rearrange args for new Apps.lazy_model_operation
    function = lambda local, related, field: operation(field, related, local)
    lazy_related_operation(function, cls, relation, field=field) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:10,代码来源:related.py

示例4: test_lazy_model_operation

# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import lazy_model_operation [as 别名]
def test_lazy_model_operation(self, apps):
        """
        Tests apps.lazy_model_operation().
        """
        model_classes = []
        initial_pending = set(apps._pending_operations)

        def test_func(*models):
            model_classes[:] = models

        class LazyA(models.Model):
            pass

        # Test models appearing twice, and models appearing consecutively
        model_keys = [('apps', model_name) for model_name in ['lazya', 'lazyb', 'lazyb', 'lazyc', 'lazya']]
        apps.lazy_model_operation(test_func, *model_keys)

        # LazyModelA shouldn't be waited on since it's already registered,
        # and LazyModelC shouldn't be waited on until LazyModelB exists.
        self.assertEqual(set(apps._pending_operations) - initial_pending, {('apps', 'lazyb')})

        # Multiple operations can wait on the same model
        apps.lazy_model_operation(test_func, ('apps', 'lazyb'))

        class LazyB(models.Model):
            pass

        self.assertEqual(model_classes, [LazyB])

        # Now we are just waiting on LazyModelC.
        self.assertEqual(set(apps._pending_operations) - initial_pending, {('apps', 'lazyc')})

        class LazyC(models.Model):
            pass

        # Everything should be loaded - make sure the callback was executed properly.
        self.assertEqual(model_classes, [LazyA, LazyB, LazyB, LazyC, LazyA]) 
开发者ID:nesdis,项目名称:djongo,代码行数:39,代码来源:tests.py


注:本文中的django.apps.apps.lazy_model_operation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。