當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。