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


Python migrations.AlterModelOptions方法代码示例

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


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

示例1: test_alter_model_options

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelOptions [as 别名]
def test_alter_model_options(self):
        """
        Tests the AlterModelOptions operation.
        """
        project_state = self.set_up_test_model("test_almoop")
        # Test the state alteration (no DB alteration to test)
        operation = migrations.AlterModelOptions("Pony", {"permissions": [("can_groom", "Can groom")]})
        self.assertEqual(operation.describe(), "Change Meta options on Pony")
        new_state = project_state.clone()
        operation.state_forwards("test_almoop", new_state)
        self.assertEqual(len(project_state.models["test_almoop", "pony"].options.get("permissions", [])), 0)
        self.assertEqual(len(new_state.models["test_almoop", "pony"].options.get("permissions", [])), 1)
        self.assertEqual(new_state.models["test_almoop", "pony"].options["permissions"][0][0], "can_groom")
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "AlterModelOptions")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'name': "Pony", 'options': {"permissions": [("can_groom", "Can groom")]}}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:test_operations.py

示例2: test_alter_model_options_emptying

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelOptions [as 别名]
def test_alter_model_options_emptying(self):
        """
        The AlterModelOptions operation removes keys from the dict (#23121)
        """
        project_state = self.set_up_test_model("test_almoop", options=True)
        # Test the state alteration (no DB alteration to test)
        operation = migrations.AlterModelOptions("Pony", {})
        self.assertEqual(operation.describe(), "Change Meta options on Pony")
        new_state = project_state.clone()
        operation.state_forwards("test_almoop", new_state)
        self.assertEqual(len(project_state.models["test_almoop", "pony"].options.get("permissions", [])), 1)
        self.assertEqual(len(new_state.models["test_almoop", "pony"].options.get("permissions", [])), 0)
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "AlterModelOptions")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'name': "Pony", 'options': {}}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:19,代码来源:test_operations.py

示例3: test_create_alter_model_options

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelOptions [as 别名]
def test_create_alter_model_options(self):
        self.assertOptimizesTo(
            [
                migrations.CreateModel('Foo', fields=[]),
                migrations.AlterModelOptions(name='Foo', options={'verbose_name_plural': 'Foozes'}),
            ],
            [
                migrations.CreateModel('Foo', fields=[], options={'verbose_name_plural': 'Foozes'}),
            ]
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:12,代码来源:test_optimizer.py

示例4: test_models_import_omitted

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelOptions [as 别名]
def test_models_import_omitted(self):
        """
        django.db.models shouldn't be imported if unused.
        """
        migration = type(str("Migration"), (migrations.Migration,), {
            "operations": [
                migrations.AlterModelOptions(
                    name='model',
                    options={'verbose_name': 'model', 'verbose_name_plural': 'models'},
                ),
            ]
        })
        writer = MigrationWriter(migration)
        output = writer.as_string()
        self.assertIn("from django.db import migrations\n", output) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:17,代码来源:test_writer.py

示例5: test_models_import_omitted

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelOptions [as 别名]
def test_models_import_omitted(self):
        """
        django.db.models shouldn't be imported if unused.
        """
        migration = type("Migration", (migrations.Migration,), {
            "operations": [
                migrations.AlterModelOptions(
                    name='model',
                    options={'verbose_name': 'model', 'verbose_name_plural': 'models'},
                ),
            ]
        })
        writer = MigrationWriter(migration)
        output = writer.as_string()
        self.assertIn("from django.db import migrations\n", output) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:test_writer.py


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