当前位置: 首页>>代码示例>>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;未经允许,请勿转载。