Python django.db.models.get_app() Examples
The following are 8
code examples of django.db.models.get_app().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.db.models
, or try the search function
.
Example #1
Source File: simple.py From anytask with MIT License | 6 votes |
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,))
Example #2
Source File: simple.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
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,))
Example #3
Source File: sql.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
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
Example #4
Source File: update_permissions.py From django-model-publisher with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)))
Example #5
Source File: base.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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)
Example #6
Source File: helper.py From cleanerversion with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: test_indexable.py From django-elasticsearch with MIT License | 5 votes |
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()
Example #8
Source File: __init__.py From yats with MIT License | 5 votes |
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)