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:
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user