當前位置: 首頁>>代碼示例>>Python>>正文


Python apps.all_models方法代碼示例

本文整理匯總了Python中django.apps.apps.all_models方法的典型用法代碼示例。如果您正苦於以下問題:Python apps.all_models方法的具體用法?Python apps.all_models怎麽用?Python apps.all_models使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.apps.apps的用法示例。


在下文中一共展示了apps.all_models方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: delete

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def delete(self, **kwargs):
        # first drop the table, we have to do this first, else
        # django will complain about no content type existing
        Model = apps.get_model("django_models_from_csv", self.name)
        ModelSchemaEditor().drop_table(Model)

        # then remove django app and content-types/permissions
        app_config = apps.get_app_config("django_models_from_csv")
        wipe_models_and_permissions(app_config, self.name)

        # finally kill the row
        super().delete(**kwargs)

        # delete it from the django app registry
        try:
            del apps.all_models["django_models_from_csv"][self.name]
        except KeyError as err:
            raise LookupError("'{}' not found.".format(self.name))

        # Unregister the model from the admin, before we wipe it out
        try:
            admin.site.unregister(Model)
        except admin.sites.NotRegistered:
            pass 
開發者ID:propublica,項目名稱:django-collaborative,代碼行數:26,代碼來源:models.py

示例2: tearDown

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def tearDown(self):
        # Taken from IsolatedModelsTestCase in
        # django/tests/invalid_models_tests/base.py
        from django.apps import apps

        apps.app_configs["tests"].models = self._old_models
        apps.all_models["tests"] = self._old_models
        apps.clear_cache() 
開發者ID:MarkusH,項目名稱:django-osm-field,代碼行數:10,代碼來源:test_fields.py

示例3: tearDown

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def tearDown(self):
        del apps.all_models['djangoseo']['dog'] 
開發者ID:whyflyru,項目名稱:django-seo,代碼行數:4,代碼來源:tests.py

示例4: test_PG_EXTRA_SEARCH_PATHS

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def test_PG_EXTRA_SEARCH_PATHS(self):
        del apps.all_models['django_tenants']
        c = connection.cursor()
        c.execute('DROP SCHEMA {0} CASCADE; CREATE SCHEMA {0};'.format(
            get_public_schema_name()
        ))
        apps.set_installed_apps(['customers', 'django_tenants']) 
開發者ID:django-tenants,項目名稱:django-tenants,代碼行數:9,代碼來源:test_settings.py

示例5: tearDown

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def tearDown(self):
        # unregister InvalidStreamModel from the overall model registry
        # so that it doesn't break tests elsewhere
        for package in ('wagtailcore', 'wagtail.core.tests'):
            try:
                del apps.all_models[package]['invalidstreammodel']
            except KeyError:
                pass
        apps.clear_cache() 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:11,代碼來源:test_streamfield.py

示例6: create_models

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def create_models():
    """
    Build & register models from the DynamicModel descriptions found
    in our database.
    """
    for dynmodel in DynamicModel.objects.all():
        model_name = dynmodel.name
        _model = construct_model(dynmodel)
        if not _model:
            logger.error("No model was created for: %s" % model_name)
            continue

        these_models = apps.all_models["django_models_from_csv"]
        these_models[model_name] = _model 
開發者ID:propublica,項目名稱:django-collaborative,代碼行數:16,代碼來源:models.py

示例7: tearDown

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def tearDown(self):
        apps.app_configs['migrations'].models = self._old_models
        apps.all_models['migrations'] = self._old_models
        apps.clear_cache()
        super(MakeMigrationsTests, self).tearDown() 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:7,代碼來源:test_commands.py

示例8: is_registered

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def is_registered(self, model_name):
        return model_name.lower() in apps.all_models[self.app_label] 
開發者ID:rvinzent,項目名稱:django-dynamic-models,代碼行數:4,代碼來源:utils.py

示例9: unregister_model

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def unregister_model(self, model_name):
        try:
            del apps.all_models[self.app_label][model_name.lower()]
        except KeyError as err:
            raise LookupError("'{}' not found.".format(model_name)) from err 
開發者ID:rvinzent,項目名稱:django-dynamic-models,代碼行數:7,代碼來源:utils.py

示例10: cleanup_registry

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def cleanup_registry():
    """
    The app registry bleeds between tests. This fixture removes all dynamically
    declared models after each test.
    """
    try:
        yield
    finally:
        app_config = apps.get_app_config(TEST_APP_LABEL)
        registered_models = app_config.get_models()
        apps.all_models[TEST_APP_LABEL].clear()
        apps.register_model(TEST_APP_LABEL, ModelSchema)
        apps.register_model(TEST_APP_LABEL, FieldSchema) 
開發者ID:rvinzent,項目名稱:django-dynamic-models,代碼行數:15,代碼來源:conftest.py

示例11: tearDown

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def tearDown(self):
        apps.app_configs['migrations'].models = self._old_models
        apps.all_models['migrations'] = self._old_models
        apps.clear_cache()
        super().tearDown() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_commands.py

示例12: test_egg1

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def test_egg1(self):
        """Models module can be loaded from an app in an egg"""
        egg_name = '%s/modelapp.egg' % self.egg_dir
        with extend_sys_path(egg_name):
            with self.settings(INSTALLED_APPS=['app_with_models']):
                models_module = apps.get_app_config('app_with_models').models_module
                self.assertIsNotNone(models_module)
        del apps.all_models['app_with_models'] 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例13: test_egg2

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def test_egg2(self):
        """Loading an app from an egg that has no models returns no models (and no error)"""
        egg_name = '%s/nomodelapp.egg' % self.egg_dir
        with extend_sys_path(egg_name):
            with self.settings(INSTALLED_APPS=['app_no_models']):
                models_module = apps.get_app_config('app_no_models').models_module
                self.assertIsNone(models_module)
        del apps.all_models['app_no_models'] 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例14: test_egg3

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def test_egg3(self):
        """Models module can be loaded from an app located under an egg's top-level package"""
        egg_name = '%s/omelet.egg' % self.egg_dir
        with extend_sys_path(egg_name):
            with self.settings(INSTALLED_APPS=['omelet.app_with_models']):
                models_module = apps.get_app_config('app_with_models').models_module
                self.assertIsNotNone(models_module)
        del apps.all_models['app_with_models'] 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py

示例15: test_egg4

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import all_models [as 別名]
def test_egg4(self):
        """Loading an app with no models from under the top-level egg package generates no error"""
        egg_name = '%s/omelet.egg' % self.egg_dir
        with extend_sys_path(egg_name):
            with self.settings(INSTALLED_APPS=['omelet.app_no_models']):
                models_module = apps.get_app_config('app_no_models').models_module
                self.assertIsNone(models_module)
        del apps.all_models['app_no_models'] 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:tests.py


注:本文中的django.apps.apps.all_models方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。