Called django.setup() explicitly in management commands.

This avoids duplicating code.
This commit is contained in:
Aymeric Augustin 2013-12-31 13:09:47 +01:00
parent 1fb873cd6b
commit 6b172a6d6d
1 changed files with 6 additions and 6 deletions

View File

@ -5,6 +5,7 @@ from optparse import OptionParser, NO_DEFAULT
import os import os
import sys import sys
import django
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError, handle_default_options from django.core.management.base import BaseCommand, CommandError, handle_default_options
@ -111,17 +112,16 @@ def get_commands():
# Find the installed apps # Find the installed apps
try: try:
installed_apps = settings.INSTALLED_APPS settings.INSTALLED_APPS
except ImproperlyConfigured: except ImproperlyConfigured:
# Still useful for commands that do not require functional # Still useful for commands that do not require functional
# settings, like startproject or help. # settings, like startproject or help.
app_names = [] app_names = []
else: else:
# Populate the app registry outside of the try/except block to # Setup Django outside of the try/except block to avoid catching
# avoid catching ImproperlyConfigured errors that aren't caused # ImproperlyConfigured errors that aren't caused by the absence of
# by the absence of a settings module. # a settings module.
from django.apps import apps django.setup()
apps.populate(installed_apps)
app_configs = apps.get_app_configs() app_configs = apps.get_app_configs()
app_names = [app_config.name for app_config in app_configs] app_names = [app_config.name for app_config in app_configs]