1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #22985 -- Made call_command accept option name parameter

Thanks giulettamasina for the report and Tim Graham for the review.
This commit is contained in:
Claude Paroz
2014-08-09 21:03:19 +02:00
parent 8f9862cd4d
commit 2cc8ffe258
5 changed files with 48 additions and 6 deletions

View File

@@ -1824,10 +1824,27 @@ Examples::
management.call_command('loaddata', 'test_data', verbosity=0)
Note that command options that take no arguments are passed as keywords
with ``True`` or ``False``::
with ``True`` or ``False``, as you can see with the ``interactive`` option above.
Named arguments can be passed by using either one of the following syntaxes::
# Similar to the command line
management.call_command('dumpdata', '--natural')
# Named argument similar to the command line minus the initial dashes and
# with internal dashes replaced by underscores
management.call_command('dumpdata', natural=True)
# `use_natural_keys` is the option destination variable
management.call_command('dumpdata', use_natural_keys=True)
.. versionchanged:: 1.8
The first syntax is now supported thanks to management commands using the
:py:mod:`argparse` module. For the second syntax, Django previously passed
the option name as-is to the command, now it is always using the ``dest``
variable name (which may or may not be the same as the option name).
Command options which take multiple options are passed a list::
management.call_command('dumpdata', exclude=['contenttypes', 'auth'])