本文整理汇总了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
示例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()
示例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']
示例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'])
示例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()
示例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
示例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()
示例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]
示例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
示例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)
示例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()
示例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']
示例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']
示例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']
示例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']