summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorNiels Van Och <niels.vanoch@gmail.com>2015-11-07 12:07:28 +0100
committerTim Graham <timograham@gmail.com>2016-01-06 18:43:41 -0500
commit7f7553dd30534d606c84952a3f6dcb64b396ce37 (patch)
treeb96009e4d8af11ff5b6255ccfbe9cd34214e74ed /django
parent0cc32a8f9782f0e465b4653012de9bc41e6d7db4 (diff)
Fixed #25680 -- Added django-admin shell --command option.
Add a -c option to the shell command to execute a command passed as a string as Django.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/shell.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py
index 7d2ce62070..dfc7d78691 100644
--- a/django/core/management/commands/shell.py
+++ b/django/core/management/commands/shell.py
@@ -18,6 +18,8 @@ class Command(BaseCommand):
help='When using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.')
parser.add_argument('-i', '--interface', choices=self.shells, dest='interface',
help='Specify an interactive interpreter interface. Available options: "ipython", "bpython", and "python"')
+ parser.add_argument('-c', '--command', dest='command',
+ help='Instead of opening an interactive shell, run a command as Django and exit.')
def _ipython_pre_011(self):
"""Start IPython pre-0.11"""
@@ -93,6 +95,11 @@ class Command(BaseCommand):
)
options['interface'] = 'python'
+ # Execute the command and exit.
+ if options['command']:
+ exec(options['command'])
+ return
+
available_shells = [options['interface']] if options['interface'] else self.shells
for shell in available_shells: