當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。