本文整理匯總了Python中django.db.models.get_app方法的典型用法代碼示例。如果您正苦於以下問題:Python models.get_app方法的具體用法?Python models.get_app怎麽用?Python models.get_app使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models
的用法示例。
在下文中一共展示了models.get_app方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_suite
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def build_suite(self, test_labels, extra_tests=None, **kwargs):
suite = unittest.TestSuite()
if test_labels:
for label in test_labels:
if '.' in label:
suite.addTest(build_test(label))
else:
app = get_app(label)
suite.addTest(build_suite(app))
else:
for app in get_apps():
suite.addTest(build_suite(app))
if extra_tests:
for test in extra_tests:
suite.addTest(test)
return reorder_suite(suite, (unittest.TestCase,))
示例2: custom_sql_for_model
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def custom_sql_for_model(model, style, connection):
opts = model._meta
app_dir = os.path.normpath(os.path.join(os.path.dirname(upath(models.get_app(model._meta.app_label).__file__)), 'sql'))
output = []
# Post-creation SQL should come before any initial SQL data is loaded.
# However, this should not be done for models that are unmanaged or
# for fields that are part of a parent model (via model inheritance).
if opts.managed:
post_sql_fields = [f for f in opts.local_fields if hasattr(f, 'post_create_sql')]
for f in post_sql_fields:
output.extend(f.post_create_sql(style, model._meta.db_table))
# Find custom SQL, if it's available.
backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)),
os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
for sql_file in sql_files:
if os.path.exists(sql_file):
with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp:
# Some backends can't execute more than one SQL statement at a time,
# so split into separate statements.
output.extend(_split_statements(fp.read()))
return output
示例3: handle
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def handle(self, *args, **options):
if not args:
apps = []
for model in get_models():
apps.append(get_app(model._meta.app_label))
else:
apps = []
for arg in args:
apps.append(get_app(arg))
for app in apps:
create_permissions(app, get_models(), int(options.get('verbosity', 0)))
示例4: handle
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def handle(self, *app_labels, **options):
from django.db import models
if not app_labels:
raise CommandError('Enter at least one appname.')
try:
app_list = [models.get_app(app_label) for app_label in app_labels]
except (ImproperlyConfigured, ImportError) as e:
raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e)
output = []
for app in app_list:
app_output = self.handle_app(app, **options)
if app_output:
output.append(app_output)
return '\n'.join(output)
示例5: get_app_models
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def get_app_models(app_name, include_auto_created=False):
if VERSION >= (1, 7):
return apps.get_app_config(app_name).get_models(
include_auto_created=include_auto_created)
else:
return get_models(get_app(app_name),
include_auto_created=include_auto_created)
示例6: setUp
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def setUp(self):
from django.db.models.signals import post_save, post_delete
try:
from django.db.models.signals import post_migrate
except ImportError: # django <= 1.6
from django.db.models.signals import post_syncdb as post_migrate
from django_elasticsearch.models import es_save_callback
from django_elasticsearch.models import es_delete_callback
from django_elasticsearch.models import es_syncdb_callback
try:
from django.apps import apps
app = apps.get_app_config('django_elasticsearch')
except ImportError: # django 1.4
from django.db.models import get_app
app = get_app('django_elasticsearch')
post_save.connect(es_save_callback)
post_delete.connect(es_delete_callback)
post_migrate.connect(es_syncdb_callback)
if int(get_version()[2]) >= 6:
sender = app
else:
sender = None
post_migrate.send(sender=sender,
app_config=app,
app=app, # django 1.4
created_models=[TestModel,],
verbosity=2)
self.instance = TestModel.objects.create(username=u"1",
first_name=u"woot",
last_name=u"foo")
self.instance.es.do_index()
示例7: update_permissions_after_migration
# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import get_app [as 別名]
def update_permissions_after_migration(app,**kwargs):
"""
Update app permission just after every migration.
This is based on app django_extensions update_permissions management command.
"""
from django.db.models import get_app, get_models
from django.contrib.auth.management import create_permissions
create_permissions(get_app(app), get_models(), 2 if settings.DEBUG else 0)