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'])

View file

@ -196,6 +196,13 @@ Management Commands
* :djadmin:`inspectdb` now outputs ``Meta.unique_together``.
* When calling management commands from code through :ref:`call_command
<call-command>` and passing options, the option name can match the command
line option name (without the initial dashes) or the final option destination
variable name, but in either case, the resulting option received by the
command is now always the ``dest`` name specified in the command option
definition (as long as the command uses the new :py:mod:`argparse` module).
Models
^^^^^^