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


Python registry.Apps方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def __init__(self, real_apps, models, ignore_swappable=False):
        # Any apps in self.real_apps should have all their models included
        # in the render. We don't use the original model instances as there
        # are some variables that refer to the Apps object.
        # FKs/M2Ms from real apps are also not included as they just
        # mess things up with partial states (due to lack of dependencies)
        self.real_models = []
        for app_label in real_apps:
            app = global_apps.get_app_config(app_label)
            for model in app.get_models():
                self.real_models.append(ModelState.from_model(model, exclude_rels=True))
        # Populate the app registry with a stub for each application.
        app_labels = {model_state.app_label for model_state in models.values()}
        app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
        super(StateApps, self).__init__(app_configs)

        self.render_multiple(list(models.values()) + self.real_models)

        # There shouldn't be any operations pending at this point.
        pending_models = set(self._pending_operations)
        if ignore_swappable:
            pending_models -= {make_model_tuple(settings.AUTH_USER_MODEL)}
        if pending_models:
            raise ValueError(self._pending_models_error(pending_models)) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:26,代码来源:state.py

示例2: test_custom_default_manager_added_to_the_model_state

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_custom_default_manager_added_to_the_model_state(self):
        """
        When the default manager of the model is a custom manager,
        it needs to be added to the model state.
        """
        new_apps = Apps(['migrations'])
        custom_manager = models.Manager()

        class Author(models.Model):
            objects = models.TextField()
            authors = custom_manager

            class Meta:
                app_label = 'migrations'
                apps = new_apps

        project_state = ProjectState.from_apps(new_apps)
        author_state = project_state.models['migrations', 'author']
        self.assertEqual(author_state.managers, [('authors', custom_manager)]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:21,代码来源:test_state.py

示例3: test_custom_default_manager_named_objects_with_false_migration_flag

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_custom_default_manager_named_objects_with_false_migration_flag(self):
        """
        When a manager is added with a name of 'objects' but it does not
        have `use_in_migrations = True`, no migration should be added to the
        model state (#26643).
        """
        new_apps = Apps(['migrations'])

        class Author(models.Model):
            objects = models.Manager()

            class Meta:
                app_label = 'migrations'
                apps = new_apps

        project_state = ProjectState.from_apps(new_apps)
        author_state = project_state.models['migrations', 'author']
        self.assertEqual(author_state.managers, []) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:test_state.py

示例4: test_custom_default_manager

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_custom_default_manager(self):
        new_apps = Apps(['migrations'])

        class Author(models.Model):
            manager1 = models.Manager()
            manager2 = models.Manager()

            class Meta:
                app_label = 'migrations'
                apps = new_apps
                default_manager_name = 'manager2'

        project_state = ProjectState.from_apps(new_apps)
        author_state = project_state.models['migrations', 'author']
        self.assertEqual(author_state.options['default_manager_name'], 'manager2')
        self.assertEqual(author_state.managers, [('manager2', Author.manager1)]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:18,代码来源:test_state.py

示例5: test_render_model_inheritance

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_render_model_inheritance(self):
        class Book(models.Model):
            title = models.CharField(max_length=1000)

            class Meta:
                app_label = "migrations"
                apps = Apps()

        class Novel(Book):
            class Meta:
                app_label = "migrations"
                apps = Apps()

        # First, test rendering individually
        apps = Apps(["migrations"])

        # We shouldn't be able to render yet
        ms = ModelState.from_model(Novel)
        with self.assertRaises(InvalidBasesError):
            ms.render(apps)

        # Once the parent model is in the app registry, it should be fine
        ModelState.from_model(Book).render(apps)
        ModelState.from_model(Novel).render(apps) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:26,代码来源:test_state.py

示例6: test_choices_iterator

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_choices_iterator(self):
        """
        #24483 - ProjectState.from_apps should not destructively consume
        Field.choices iterators.
        """
        new_apps = Apps(["migrations"])
        choices = [('a', 'A'), ('b', 'B')]

        class Author(models.Model):
            name = models.CharField(max_length=255)
            choice = models.CharField(max_length=255, choices=iter(choices))

            class Meta:
                app_label = "migrations"
                apps = new_apps

        ProjectState.from_apps(new_apps)
        choices_field = Author._meta.get_field('choice')
        self.assertEqual(list(choices_field.choices), choices) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:21,代码来源:test_state.py

示例7: test_custom_manager_swappable

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_custom_manager_swappable(self):
        """
        Tests making a ProjectState from unused models with custom managers
        """
        new_apps = Apps(['migrations'])

        class Food(models.Model):

            food_mgr = FoodManager('a', 'b')
            food_qs = FoodQuerySet.as_manager()
            food_no_mgr = NoMigrationFoodManager('x', 'y')

            class Meta:
                app_label = "migrations"
                apps = new_apps
                swappable = 'TEST_SWAPPABLE_MODEL'

        food_state = ModelState.from_model(Food)

        # The default manager is used in migrations
        self.assertEqual([name for name, mgr in food_state.managers], ['food_mgr'])
        self.assertEqual(food_state.managers[0][1].args, ('a', 'b', 1, 2)) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:24,代码来源:test_state.py

示例8: test_dynamic_load

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def test_dynamic_load(self):
        """
        Makes a new model at runtime and ensures it goes into the right place.
        """
        old_models = list(apps.get_app_config("apps").get_models())
        # Construct a new model in a new app registry
        body = {}
        new_apps = Apps(["apps"])
        meta_contents = {
            'app_label': "apps",
            'apps': new_apps,
        }
        meta = type("Meta", (), meta_contents)
        body['Meta'] = meta
        body['__module__'] = TotallyNormal.__module__
        temp_model = type("SouthPonies", (models.Model,), body)
        # Make sure it appeared in the right place!
        self.assertEqual(list(apps.get_app_config("apps").get_models()), old_models)
        with self.assertRaises(LookupError):
            apps.get_model("apps", "SouthPonies")
        self.assertEqual(new_apps.get_model("apps", "SouthPonies"), temp_model) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:tests.py

示例9: __init__

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def __init__(self, models=None, real_apps=None):
        self.models = models or {}
        # Apps to include from main registry, usually unmigrated ones
        self.real_apps = real_apps or [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:state.py

示例10: from_apps

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def from_apps(cls, apps):
        "Takes in an Apps and returns a ProjectState matching it"
        app_models = {}
        for model in apps.get_models(include_swapped=True):
            model_state = ModelState.from_model(model)
            app_models[(model_state.app_label, model_state.name_lower)] = model_state
        return cls(app_models) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:state.py

示例11: __init__

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def __init__(self, models=None, real_apps=None):
        self.models = models or {}
        # Apps to include from main registry, usually unmigrated ones
        self.real_apps = real_apps or []
        self.is_delayed = False 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:7,代码来源:state.py

示例12: from_apps

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def from_apps(cls, apps):
        """Take an Apps and return a ProjectState matching it."""
        app_models = {}
        for model in apps.get_models(include_swapped=True):
            model_state = ModelState.from_model(model)
            app_models[(model_state.app_label, model_state.name_lower)] = model_state
        return cls(app_models) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:9,代码来源:state.py

示例13: enable

# 需要导入模块: from django.apps import registry [as 别名]
# 或者: from django.apps.registry import Apps [as 别名]
def enable(self):
        self.old_apps = Options.default_apps
        apps = Apps(self.installed_apps)
        setattr(Options, 'default_apps', apps)
        return apps 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:7,代码来源:utils.py


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