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


Python questioner.MigrationQuestioner方法代码示例

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


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

示例1: test_trim_apps

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_trim_apps(self):
        """
        Trim does not remove dependencies but does remove unwanted apps.
        """
        # Use project state to make a new migration change set
        before = self.make_project_state([])
        after = self.make_project_state([self.author_empty, self.other_pony, self.other_stable, self.third_thing])
        autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_initial": True}))
        changes = autodetector._detect_changes()
        # Run through arrange_for_graph
        graph = MigrationGraph()
        changes = autodetector.arrange_for_graph(changes, graph)
        changes["testapp"][0].dependencies.append(("otherapp", "0001_initial"))
        changes = autodetector._trim_to_apps(changes, {"testapp"})
        # Make sure there's the right set of migrations
        self.assertEqual(changes["testapp"][0].name, "0001_initial")
        self.assertEqual(changes["otherapp"][0].name, "0001_initial")
        self.assertNotIn("thirdapp", changes) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:test_autodetector.py

示例2: test_rename_field_and_foo_together

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_field_and_foo_together(self):
        """
        Removed fields will be removed after updating index/unique_together.
        """
        changes = self.get_changes(
            [self.author_empty, self.book_foo_together_3],
            [self.author_empty, self.book_foo_together_4],
            MigrationQuestioner({"ask_rename": True}),
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, "otherapp", 1)
        self.assertOperationTypes(changes, "otherapp", 0, ["RenameField", "AlterUniqueTogether", "AlterIndexTogether"])
        self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", unique_together={
            ("title", "newfield2")
        })
        self.assertOperationAttributes(changes, "otherapp", 0, 2, name="book", index_together={("title", "newfield2")}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:18,代码来源:test_autodetector.py

示例3: test_rename_model_with_renamed_rel_field

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_model_with_renamed_rel_field(self):
        """
        Tests autodetection of renamed models while simultaneously renaming one
        of the fields that relate to the renamed model.
        """
        changes = self.get_changes(
            [self.author_with_book, self.book],
            [self.author_renamed_with_book, self.book_with_field_and_author_renamed],
            MigrationQuestioner({"ask_rename": True, "ask_rename_model": True}),
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel"])
        self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name="Author", new_name="Writer")
        # Right number/type of migrations for related field rename?
        # Alter is already taken care of.
        self.assertNumberMigrations(changes, 'otherapp', 1)
        self.assertOperationTypes(changes, 'otherapp', 0, ["RenameField"])
        self.assertOperationAttributes(changes, 'otherapp', 0, 0, old_name="author", new_name="writer") 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_autodetector.py

示例4: __init__

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def __init__(self, from_state, to_state, questioner=None):
        self.from_state = from_state
        self.to_state = to_state
        self.questioner = questioner or MigrationQuestioner() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:autodetector.py

示例5: __init__

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def __init__(self, from_state, to_state, questioner=None):
        self.from_state = from_state
        self.to_state = to_state
        self.questioner = questioner or MigrationQuestioner()
        self.existing_apps = {app for app, model in from_state.models} 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:7,代码来源:autodetector.py

示例6: test_ask_initial_with_disabled_migrations

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_ask_initial_with_disabled_migrations(self):
        questioner = MigrationQuestioner()
        self.assertIs(False, questioner.ask_initial('migrations')) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:5,代码来源:test_questioner.py

示例7: test_rename_field

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_field(self):
        """Tests autodetection of renamed fields."""
        changes = self.get_changes(
            [self.author_name], [self.author_name_renamed], MigrationQuestioner({"ask_rename": True})
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ["RenameField"])
        self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name="name", new_name="names") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:11,代码来源:test_autodetector.py

示例8: test_rename_model

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_model(self):
        """Tests autodetection of renamed models."""
        changes = self.get_changes(
            [self.author_with_book, self.book],
            [self.author_renamed_with_book, self.book_with_author_renamed],
            MigrationQuestioner({"ask_rename_model": True}),
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel"])
        self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name="Author", new_name="Writer")
        # Now that RenameModel handles related fields too, there should be
        # no AlterField for the related field.
        self.assertNumberMigrations(changes, 'otherapp', 0) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:16,代码来源:test_autodetector.py

示例9: test_rename_m2m_through_model

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_m2m_through_model(self):
        """
        Tests autodetection of renamed models that are used in M2M relations as
        through models.
        """
        changes = self.get_changes(
            [self.author_with_m2m_through, self.publisher, self.contract],
            [self.author_with_renamed_m2m_through, self.publisher, self.contract_renamed],
            MigrationQuestioner({'ask_rename_model': True})
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ['RenameModel'])
        self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name='Contract', new_name='Deal') 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:16,代码来源:test_autodetector.py

示例10: test_rename_model_with_fks_in_different_position

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_model_with_fks_in_different_position(self):
        """
        #24537 - The order of fields in a model does not influence
        the RenameModel detection.
        """
        before = [
            ModelState("testapp", "EntityA", [
                ("id", models.AutoField(primary_key=True)),
            ]),
            ModelState("testapp", "EntityB", [
                ("id", models.AutoField(primary_key=True)),
                ("some_label", models.CharField(max_length=255)),
                ("entity_a", models.ForeignKey("testapp.EntityA", models.CASCADE)),
            ]),
        ]
        after = [
            ModelState("testapp", "EntityA", [
                ("id", models.AutoField(primary_key=True)),
            ]),
            ModelState("testapp", "RenamedEntityB", [
                ("id", models.AutoField(primary_key=True)),
                ("entity_a", models.ForeignKey("testapp.EntityA", models.CASCADE)),
                ("some_label", models.CharField(max_length=255)),
            ]),
        ]
        changes = self.get_changes(before, after, MigrationQuestioner({"ask_rename_model": True}))
        self.assertNumberMigrations(changes, "testapp", 1)
        self.assertOperationTypes(changes, "testapp", 0, ["RenameModel"])
        self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="EntityB", new_name="RenamedEntityB") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:31,代码来源:test_autodetector.py

示例11: test_keep_db_table_with_model_change

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_keep_db_table_with_model_change(self):
        """
        Tests when model changes but db_table stays as-is, autodetector must not
        create more than one operation.
        """
        changes = self.get_changes(
            [self.author_with_db_table_options],
            [self.author_renamed_with_db_table_options],
            MigrationQuestioner({"ask_rename_model": True}),
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel"])
        self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="Author", new_name="NewAuthor") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:16,代码来源:test_autodetector.py

示例12: test_alter_db_table_with_model_change

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_alter_db_table_with_model_change(self):
        """
        Tests when model and db_table changes, autodetector must create two
        operations.
        """
        changes = self.get_changes(
            [self.author_with_db_table_options],
            [self.author_renamed_with_new_db_table_options],
            MigrationQuestioner({"ask_rename_model": True}),
        )
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel", "AlterModelTable"])
        self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="Author", new_name="NewAuthor")
        self.assertOperationAttributes(changes, "testapp", 0, 1, name="newauthor", table="author_three") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:17,代码来源:test_autodetector.py

示例13: test_rename_field_foreign_key_to_field

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_field_foreign_key_to_field(self):
        before = [
            ModelState('app', 'Foo', [
                ('id', models.AutoField(primary_key=True)),
                ('field', models.IntegerField(unique=True)),
            ]),
            ModelState('app', 'Bar', [
                ('id', models.AutoField(primary_key=True)),
                ('foo', models.ForeignKey('app.Foo', models.CASCADE, to_field='field')),
            ]),
        ]
        after = [
            ModelState('app', 'Foo', [
                ('id', models.AutoField(primary_key=True)),
                ('renamed_field', models.IntegerField(unique=True)),
            ]),
            ModelState('app', 'Bar', [
                ('id', models.AutoField(primary_key=True)),
                ('foo', models.ForeignKey('app.Foo', models.CASCADE, to_field='renamed_field')),
            ]),
        ]
        changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename': True}))
        # Right number/type of migrations?
        self.assertNumberMigrations(changes, 'app', 1)
        self.assertOperationTypes(changes, 'app', 0, ['RenameField'])
        self.assertOperationAttributes(changes, 'app', 0, 0, old_name='field', new_name='renamed_field') 
开发者ID:nesdis,项目名称:djongo,代码行数:28,代码来源:test_autodetector.py

示例14: test_rename_field_preserved_db_column

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_field_preserved_db_column(self):
        """
        RenameField is used if a field is renamed and db_column equal to the
        old field's column is added.
        """
        before = [
            ModelState('app', 'Foo', [
                ('id', models.AutoField(primary_key=True)),
                ('field', models.IntegerField()),
            ]),
        ]
        after = [
            ModelState('app', 'Foo', [
                ('id', models.AutoField(primary_key=True)),
                ('renamed_field', models.IntegerField(db_column='field')),
            ]),
        ]
        changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename': True}))
        self.assertNumberMigrations(changes, 'app', 1)
        self.assertOperationTypes(changes, 'app', 0, ['RenameField', 'AlterField'])
        self.assertOperationAttributes(
            changes, 'app', 0, 0, model_name='foo', old_name='field', new_name='renamed_field',
        )
        self.assertOperationAttributes(changes, 'app', 0, 1, model_name='foo', name='renamed_field')
        self.assertEqual(changes['app'][0].operations[-1].field.deconstruct(), (
            'renamed_field', 'django.db.models.IntegerField', [], {'db_column': 'field'},
        )) 
开发者ID:nesdis,项目名称:djongo,代码行数:29,代码来源:test_autodetector.py

示例15: test_rename_model_reverse_relation_dependencies

# 需要导入模块: from django.db.migrations import questioner [as 别名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 别名]
def test_rename_model_reverse_relation_dependencies(self):
        """
        The migration to rename a model pointed to by a foreign key in another
        app must run after the other app's migration that adds the foreign key
        with model's original name. Therefore, the renaming migration has a
        dependency on that other migration.
        """
        before = [
            ModelState('testapp', 'EntityA', [
                ('id', models.AutoField(primary_key=True)),
            ]),
            ModelState('otherapp', 'EntityB', [
                ('id', models.AutoField(primary_key=True)),
                ('entity_a', models.ForeignKey('testapp.EntityA', models.CASCADE)),
            ]),
        ]
        after = [
            ModelState('testapp', 'RenamedEntityA', [
                ('id', models.AutoField(primary_key=True)),
            ]),
            ModelState('otherapp', 'EntityB', [
                ('id', models.AutoField(primary_key=True)),
                ('entity_a', models.ForeignKey('testapp.RenamedEntityA', models.CASCADE)),
            ]),
        ]
        changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename_model': True}))
        self.assertNumberMigrations(changes, 'testapp', 1)
        self.assertMigrationDependencies(changes, 'testapp', 0, [('otherapp', '__first__')])
        self.assertOperationTypes(changes, 'testapp', 0, ['RenameModel'])
        self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name='EntityA', new_name='RenamedEntityA') 
开发者ID:nesdis,项目名称:djongo,代码行数:32,代码来源:test_autodetector.py


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