1
0
mirror of https://github.com/django/django.git synced 2025-10-26 23:26:08 +00:00

[1.7.x] Fixed #22770 -- Removed create_superuser from post_migrate signals.

Moved logic to syncdb command for backwards compatibility.

Backport of 93d05536fd from master
This commit is contained in:
Tim Graham
2014-06-10 12:22:07 -04:00
parent d232a5f93f
commit 0767055dfc
6 changed files with 60 additions and 74 deletions

View File

@@ -1,10 +1,13 @@
import warnings
from optparse import make_option
from django.apps import apps
from django.contrib.auth import get_user_model
from django.db import DEFAULT_DB_ALIAS
from django.core.management import call_command
from django.core.management.base import NoArgsCommand
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.six.moves import input
class Command(NoArgsCommand):
@@ -22,3 +25,23 @@ class Command(NoArgsCommand):
def handle_noargs(self, **options):
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
call_command("migrate", **options)
try:
apps.get_model('auth', 'Permission')
except LookupError:
return
UserModel = get_user_model()
if not UserModel._default_manager.exists() and options.get('interactive'):
msg = ("\nYou have installed Django's auth system, and "
"don't have any superusers defined.\nWould you like to create one "
"now? (yes/no): ")
confirm = input(msg)
while 1:
if confirm not in ('yes', 'no'):
confirm = input('Please enter either "yes" or "no": ')
continue
if confirm == 'yes':
call_command("createsuperuser", interactive=True, database=options['database'])
break