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


Python migrations.RenameModel方法代码示例

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


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

示例1: test_optimize_through_fields

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_optimize_through_fields(self):
        """
        field-level through checking is working. This should manage to collapse
        model Foo to nonexistence, and model Bar to a single IntegerField
        called "width".
        """
        self.assertOptimizesTo(
            [
                migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
                migrations.CreateModel("Bar", [("size", models.IntegerField())]),
                migrations.AddField("Foo", "age", models.IntegerField()),
                migrations.AddField("Bar", "width", models.IntegerField()),
                migrations.AlterField("Foo", "age", models.IntegerField()),
                migrations.RenameField("Bar", "size", "dimensions"),
                migrations.RemoveField("Foo", "age"),
                migrations.RenameModel("Foo", "Phou"),
                migrations.RemoveField("Bar", "dimensions"),
                migrations.RenameModel("Phou", "Fou"),
                migrations.DeleteModel("Fou"),
            ],
            [
                migrations.CreateModel("Bar", [("width", models.IntegerField())]),
            ],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:26,代码来源:test_optimizer.py

示例2: test_optimize_elidable_operation

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_optimize_elidable_operation(self):
        elidable_operation = operations.base.Operation()
        elidable_operation.elidable = True
        self.assertOptimizesTo(
            [
                elidable_operation,
                migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
                elidable_operation,
                migrations.CreateModel("Bar", [("size", models.IntegerField())]),
                elidable_operation,
                migrations.RenameModel("Foo", "Phou"),
                migrations.DeleteModel("Bar"),
                elidable_operation,
            ],
            [
                migrations.CreateModel("Phou", [("name", models.CharField(max_length=255))]),
            ],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:test_optimizer.py

示例3: test_rename_model_state_forwards

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_state_forwards(self):
        """
        RenameModel operations shouldn't trigger the caching of rendered apps
        on state without prior apps.
        """
        state = ProjectState()
        state.add_model(ModelState('migrations', 'Foo', []))
        operation = migrations.RenameModel('Foo', 'Bar')
        operation.state_forwards('migrations', state)
        self.assertNotIn('apps', state.__dict__)
        self.assertNotIn(('migrations', 'foo'), state.models)
        self.assertIn(('migrations', 'bar'), state.models)
        # Now with apps cached.
        apps = state.apps
        operation = migrations.RenameModel('Bar', 'Foo')
        operation.state_forwards('migrations', state)
        self.assertIs(state.apps, apps)
        self.assertNotIn(('migrations', 'bar'), state.models)
        self.assertIn(('migrations', 'foo'), state.models) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_operations.py

示例4: reduce_model_rename_self

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def reduce_model_rename_self(self, operation, other, in_between):
        """
        Folds a model rename into another one
        """
        if operation.new_name_lower == other.old_name_lower:
            return [
                migrations.RenameModel(
                    operation.old_name,
                    other.new_name,
                )
            ] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:optimizer.py

示例5: test_create_rename_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_create_rename_model(self):
        """
        CreateModel should absorb RenameModels.
        """
        managers = [('objects', EmptyManager())]
        self.assertOptimizesTo(
            [
                migrations.CreateModel(
                    name="Foo",
                    fields=[("name", models.CharField(max_length=255))],
                    options={'verbose_name': 'Foo'},
                    bases=(UnicodeModel,),
                    managers=managers,
                ),
                migrations.RenameModel("Foo", "Bar"),
            ],
            [
                migrations.CreateModel(
                    "Bar",
                    [("name", models.CharField(max_length=255))],
                    options={'verbose_name': 'Foo'},
                    bases=(UnicodeModel,),
                    managers=managers,
                )
            ],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:28,代码来源:test_optimizer.py

示例6: test_rename_model_self

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_self(self):
        """
        RenameModels should absorb themselves.
        """
        self.assertOptimizesTo(
            [
                migrations.RenameModel("Foo", "Baa"),
                migrations.RenameModel("Baa", "Bar"),
            ],
            [
                migrations.RenameModel("Foo", "Bar"),
            ],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:15,代码来源:test_optimizer.py

示例7: test_rename_model_with_self_referential_fk

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_self_referential_fk(self):
        """
        Tests the RenameModel operation on model with self referential FK.
        """
        project_state = self.set_up_test_model("test_rmwsrf", related_model=True)
        # Test the state alteration
        operation = migrations.RenameModel("Rider", "HorseRider")
        self.assertEqual(operation.describe(), "Rename model Rider to HorseRider")
        new_state = project_state.clone()
        operation.state_forwards("test_rmwsrf", new_state)
        self.assertNotIn(("test_rmwsrf", "rider"), new_state.models)
        self.assertIn(("test_rmwsrf", "horserider"), new_state.models)
        # Remember, RenameModel also repoints all incoming FKs and M2Ms
        self.assertEqual(
            'self',
            new_state.models["test_rmwsrf", "horserider"].fields[2][1].remote_field.model
        )
        HorseRider = new_state.apps.get_model('test_rmwsrf', 'horserider')
        self.assertIs(HorseRider._meta.get_field('horserider').remote_field.model, HorseRider)
        # Test the database alteration
        self.assertTableExists("test_rmwsrf_rider")
        self.assertTableNotExists("test_rmwsrf_horserider")
        if connection.features.supports_foreign_keys:
            self.assertFKExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_rider", "id"))
            self.assertFKNotExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_horserider", "id"))
        with connection.schema_editor() as editor:
            operation.database_forwards("test_rmwsrf", editor, project_state, new_state)
        self.assertTableNotExists("test_rmwsrf_rider")
        self.assertTableExists("test_rmwsrf_horserider")
        if connection.features.supports_foreign_keys:
            self.assertFKNotExists("test_rmwsrf_horserider", ["friend_id"], ("test_rmwsrf_rider", "id"))
            self.assertFKExists("test_rmwsrf_horserider", ["friend_id"], ("test_rmwsrf_horserider", "id"))
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_rmwsrf", editor, new_state, project_state)
        self.assertTableExists("test_rmwsrf_rider")
        self.assertTableNotExists("test_rmwsrf_horserider")
        if connection.features.supports_foreign_keys:
            self.assertFKExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_rider", "id"))
            self.assertFKNotExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_horserider", "id")) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:42,代码来源:test_operations.py

示例8: test_rename_model_with_superclass_fk

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_superclass_fk(self):
        """
        Tests the RenameModel operation on a model which has a superclass that
        has a foreign key.
        """
        project_state = self.set_up_test_model("test_rmwsc", related_model=True, mti_model=True)
        # Test the state alteration
        operation = migrations.RenameModel("ShetlandPony", "LittleHorse")
        self.assertEqual(operation.describe(), "Rename model ShetlandPony to LittleHorse")
        new_state = project_state.clone()
        operation.state_forwards("test_rmwsc", new_state)
        self.assertNotIn(("test_rmwsc", "shetlandpony"), new_state.models)
        self.assertIn(("test_rmwsc", "littlehorse"), new_state.models)
        # RenameModel shouldn't repoint the superclass's relations, only local ones
        self.assertEqual(
            project_state.models["test_rmwsc", "rider"].fields[1][1].remote_field.model,
            new_state.models["test_rmwsc", "rider"].fields[1][1].remote_field.model
        )
        # Before running the migration we have a table for Shetland Pony, not Little Horse
        self.assertTableExists("test_rmwsc_shetlandpony")
        self.assertTableNotExists("test_rmwsc_littlehorse")
        if connection.features.supports_foreign_keys:
            # and the foreign key on rider points to pony, not shetland pony
            self.assertFKExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_pony", "id"))
            self.assertFKNotExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_shetlandpony", "id"))
        with connection.schema_editor() as editor:
            operation.database_forwards("test_rmwsc", editor, project_state, new_state)
        # Now we have a little horse table, not shetland pony
        self.assertTableNotExists("test_rmwsc_shetlandpony")
        self.assertTableExists("test_rmwsc_littlehorse")
        if connection.features.supports_foreign_keys:
            # but the Foreign keys still point at pony, not little horse
            self.assertFKExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_pony", "id"))
            self.assertFKNotExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_littlehorse", "id")) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:36,代码来源:test_operations.py

示例9: test_rename_model_with_self_referential_m2m

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_self_referential_m2m(self):
        app_label = "test_rename_model_with_self_referential_m2m"

        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel("ReflexivePony", fields=[
                ("id", models.AutoField(primary_key=True)),
                ("ponies", models.ManyToManyField("self")),
            ]),
        ])
        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.RenameModel("ReflexivePony", "ReflexivePony2"),
        ])
        Pony = project_state.apps.get_model(app_label, "ReflexivePony2")
        pony = Pony.objects.create()
        pony.ponies.add(pony) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:17,代码来源:test_operations.py

示例10: test_rename_model_with_m2m

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_m2m(self):
        app_label = "test_rename_model_with_m2m"
        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel("Rider", fields=[
                ("id", models.AutoField(primary_key=True)),
            ]),
            migrations.CreateModel("Pony", fields=[
                ("id", models.AutoField(primary_key=True)),
                ("riders", models.ManyToManyField("Rider")),
            ]),
        ])
        Pony = project_state.apps.get_model(app_label, "Pony")
        Rider = project_state.apps.get_model(app_label, "Rider")
        pony = Pony.objects.create()
        rider = Rider.objects.create()
        pony.riders.add(rider)

        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.RenameModel("Pony", "Pony2"),
        ])
        Pony = project_state.apps.get_model(app_label, "Pony2")
        Rider = project_state.apps.get_model(app_label, "Rider")
        pony = Pony.objects.create()
        rider = Rider.objects.create()
        pony.riders.add(rider)
        self.assertEqual(Pony.objects.count(), 2)
        self.assertEqual(Rider.objects.count(), 2)
        self.assertEqual(Pony._meta.get_field('riders').remote_field.through.objects.count(), 2) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:30,代码来源:test_operations.py

示例11: test_rename_m2m_target_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_m2m_target_model(self):
        app_label = "test_rename_m2m_target_model"
        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel("Rider", fields=[
                ("id", models.AutoField(primary_key=True)),
            ]),
            migrations.CreateModel("Pony", fields=[
                ("id", models.AutoField(primary_key=True)),
                ("riders", models.ManyToManyField("Rider")),
            ]),
        ])
        Pony = project_state.apps.get_model(app_label, "Pony")
        Rider = project_state.apps.get_model(app_label, "Rider")
        pony = Pony.objects.create()
        rider = Rider.objects.create()
        pony.riders.add(rider)

        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.RenameModel("Rider", "Rider2"),
        ])
        Pony = project_state.apps.get_model(app_label, "Pony")
        Rider = project_state.apps.get_model(app_label, "Rider2")
        pony = Pony.objects.create()
        rider = Rider.objects.create()
        pony.riders.add(rider)
        self.assertEqual(Pony.objects.count(), 2)
        self.assertEqual(Rider.objects.count(), 2)
        self.assertEqual(Pony._meta.get_field('riders').remote_field.through.objects.count(), 2) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:30,代码来源:test_operations.py

示例12: test_rename_model_with_self_referential_fk

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_self_referential_fk(self):
        """
        Tests the RenameModel operation on model with self referential FK.
        """
        project_state = self.set_up_test_model("test_rmwsrf", related_model=True)
        # Test the state alteration
        operation = migrations.RenameModel("Rider", "HorseRider")
        self.assertEqual(operation.describe(), "Rename model Rider to HorseRider")
        new_state = project_state.clone()
        operation.state_forwards("test_rmwsrf", new_state)
        self.assertNotIn(("test_rmwsrf", "rider"), new_state.models)
        self.assertIn(("test_rmwsrf", "horserider"), new_state.models)
        # Remember, RenameModel also repoints all incoming FKs and M2Ms
        self.assertEqual(
            'self',
            new_state.models["test_rmwsrf", "horserider"].fields[2][1].remote_field.model
        )
        HorseRider = new_state.apps.get_model('test_rmwsrf', 'horserider')
        self.assertIs(HorseRider._meta.get_field('horserider').remote_field.model, HorseRider)
        # Test the database alteration
        self.assertTableExists("test_rmwsrf_rider")
        self.assertTableNotExists("test_rmwsrf_horserider")
        if connection.features.supports_foreign_keys:
            self.assertFKExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_rider", "id"))
            self.assertFKNotExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_horserider", "id"))
        atomic_rename = connection.features.supports_atomic_references_rename
        with connection.schema_editor(atomic=atomic_rename) as editor:
            operation.database_forwards("test_rmwsrf", editor, project_state, new_state)
        self.assertTableNotExists("test_rmwsrf_rider")
        self.assertTableExists("test_rmwsrf_horserider")
        if connection.features.supports_foreign_keys:
            self.assertFKNotExists("test_rmwsrf_horserider", ["friend_id"], ("test_rmwsrf_rider", "id"))
            self.assertFKExists("test_rmwsrf_horserider", ["friend_id"], ("test_rmwsrf_horserider", "id"))
        # And test reversal
        with connection.schema_editor(atomic=atomic_rename) as editor:
            operation.database_backwards("test_rmwsrf", editor, new_state, project_state)
        self.assertTableExists("test_rmwsrf_rider")
        self.assertTableNotExists("test_rmwsrf_horserider")
        if connection.features.supports_foreign_keys:
            self.assertFKExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_rider", "id"))
            self.assertFKNotExists("test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_horserider", "id")) 
开发者ID:nesdis,项目名称:djongo,代码行数:43,代码来源:test_operations.py

示例13: test_rename_model_with_superclass_fk

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_superclass_fk(self):
        """
        Tests the RenameModel operation on a model which has a superclass that
        has a foreign key.
        """
        project_state = self.set_up_test_model("test_rmwsc", related_model=True, mti_model=True)
        # Test the state alteration
        operation = migrations.RenameModel("ShetlandPony", "LittleHorse")
        self.assertEqual(operation.describe(), "Rename model ShetlandPony to LittleHorse")
        new_state = project_state.clone()
        operation.state_forwards("test_rmwsc", new_state)
        self.assertNotIn(("test_rmwsc", "shetlandpony"), new_state.models)
        self.assertIn(("test_rmwsc", "littlehorse"), new_state.models)
        # RenameModel shouldn't repoint the superclass's relations, only local ones
        self.assertEqual(
            project_state.models["test_rmwsc", "rider"].fields[1][1].remote_field.model,
            new_state.models["test_rmwsc", "rider"].fields[1][1].remote_field.model
        )
        # Before running the migration we have a table for Shetland Pony, not Little Horse
        self.assertTableExists("test_rmwsc_shetlandpony")
        self.assertTableNotExists("test_rmwsc_littlehorse")
        if connection.features.supports_foreign_keys:
            # and the foreign key on rider points to pony, not shetland pony
            self.assertFKExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_pony", "id"))
            self.assertFKNotExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_shetlandpony", "id"))
        with connection.schema_editor(atomic=connection.features.supports_atomic_references_rename) as editor:
            operation.database_forwards("test_rmwsc", editor, project_state, new_state)
        # Now we have a little horse table, not shetland pony
        self.assertTableNotExists("test_rmwsc_shetlandpony")
        self.assertTableExists("test_rmwsc_littlehorse")
        if connection.features.supports_foreign_keys:
            # but the Foreign keys still point at pony, not little horse
            self.assertFKExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_pony", "id"))
            self.assertFKNotExists("test_rmwsc_rider", ["pony_id"], ("test_rmwsc_littlehorse", "id")) 
开发者ID:nesdis,项目名称:djongo,代码行数:36,代码来源:test_operations.py

示例14: test_rename_model_with_self_referential_m2m

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_self_referential_m2m(self):
        app_label = "test_rename_model_with_self_referential_m2m"

        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel("ReflexivePony", fields=[
                ("id", models.AutoField(primary_key=True)),
                ("ponies", models.ManyToManyField("self")),
            ]),
        ])
        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.RenameModel("ReflexivePony", "ReflexivePony2"),
        ], atomic=connection.features.supports_atomic_references_rename)
        Pony = project_state.apps.get_model(app_label, "ReflexivePony2")
        pony = Pony.objects.create()
        pony.ponies.add(pony) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:test_operations.py

示例15: test_rename_model_with_m2m

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import RenameModel [as 别名]
def test_rename_model_with_m2m(self):
        app_label = "test_rename_model_with_m2m"
        project_state = self.apply_operations(app_label, ProjectState(), operations=[
            migrations.CreateModel("Rider", fields=[
                ("id", models.AutoField(primary_key=True)),
            ]),
            migrations.CreateModel("Pony", fields=[
                ("id", models.AutoField(primary_key=True)),
                ("riders", models.ManyToManyField("Rider")),
            ]),
        ])
        Pony = project_state.apps.get_model(app_label, "Pony")
        Rider = project_state.apps.get_model(app_label, "Rider")
        pony = Pony.objects.create()
        rider = Rider.objects.create()
        pony.riders.add(rider)

        project_state = self.apply_operations(app_label, project_state, operations=[
            migrations.RenameModel("Pony", "Pony2"),
        ], atomic=connection.features.supports_atomic_references_rename)
        Pony = project_state.apps.get_model(app_label, "Pony2")
        Rider = project_state.apps.get_model(app_label, "Rider")
        pony = Pony.objects.create()
        rider = Rider.objects.create()
        pony.riders.add(rider)
        self.assertEqual(Pony.objects.count(), 2)
        self.assertEqual(Rider.objects.count(), 2)
        self.assertEqual(Pony._meta.get_field('riders').remote_field.through.objects.count(), 2) 
开发者ID:nesdis,项目名称:djongo,代码行数:30,代码来源:test_operations.py


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