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


Python migrations.swappable_dependency方法代碼示例

本文整理匯總了Python中django.db.migrations.swappable_dependency方法的典型用法代碼示例。如果您正苦於以下問題:Python migrations.swappable_dependency方法的具體用法?Python migrations.swappable_dependency怎麽用?Python migrations.swappable_dependency使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.migrations的用法示例。


在下文中一共展示了migrations.swappable_dependency方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: dependency

# 需要導入模塊: from django.db import migrations [as 別名]
# 或者: from django.db.migrations import swappable_dependency [as 別名]
def dependency(app_label, model):
    """
    Returns a Django 1.7+ style dependency tuple for inclusion in
    migration.dependencies[]
    """
    from django.db.migrations import swappable_dependency
    return swappable_dependency(get_model_name(app_label, model)) 
開發者ID:wq,項目名稱:django-swappable-models,代碼行數:9,代碼來源:__init__.py

示例2: as_string

# 需要導入模塊: from django.db import migrations [as 別名]
# 或者: from django.db.migrations import swappable_dependency [as 別名]
def as_string(self):
        """
        Returns a string of the file contents.
        """
        items = {
            "replaces_str": "",
        }

        imports = set()

        # Deconstruct operations
        operations = []
        for operation in self.migration.operations:
            operation_string, operation_imports = OperationWriter(operation).serialize()
            imports.update(operation_imports)
            operations.append(operation_string)
        items["operations"] = "\n".join(operations) + "\n" if operations else ""

        # Format dependencies and write out swappable dependencies right
        dependencies = []
        for dependency in self.migration.dependencies:
            if dependency[0] == "__setting__":
                dependencies.append("        migrations.swappable_dependency(settings.%s)," % dependency[1])
                imports.add("from django.conf import settings")
            else:
                # No need to output bytestrings for dependencies
                dependency = tuple(force_text(s) for s in dependency)
                dependencies.append("        %s," % self.serialize(dependency)[0])
        items["dependencies"] = "\n".join(dependencies) + "\n" if dependencies else ""

        # Format imports nicely, swapping imports of functions from migration files
        # for comments
        migration_imports = set()
        for line in list(imports):
            if re.match("^import (.*)\.\d+[^\s]*$", line):
                migration_imports.add(line.split("import")[1].strip())
                imports.remove(line)
                self.needs_manual_porting = True
        imports.discard("from django.db import models")
        items["imports"] = "\n".join(imports) + "\n" if imports else ""
        if migration_imports:
            items["imports"] += (
                "\n\n# Functions from the following migrations need manual "
                "copying.\n# Move them and any dependencies into this file, "
                "then update the\n# RunPython operations to refer to the local "
                "versions:\n# %s"
            ) % "\n# ".join(migration_imports)
        # If there's a replaces, make a string for it
        if self.migration.replaces:
            items['replaces_str'] = "\n    replaces = %s\n" % self.serialize(self.migration.replaces)[0]

        return (MIGRATION_TEMPLATE % items).encode("utf8") 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:54,代碼來源:writer.py


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