Escolar Documentos
Profissional Documentos
Cultura Documentos
.. code-block:: python
class Command(BaseCommand):
def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
# ...
.. method:: BaseCommand.get_version()
Return the Django version, which should be correct for all
built-in Django commands. User-supplied commands can
override this method to return their own version.
.. method:: BaseCommand.execute(*args, **options)
Try to execute this command, performing model validation if
needed (as controlled by the attribute
:attr:`requires_model_validation`). If the command raises a
:class:`CommandError`, intercept it and print it sensibly to
stderr.
.. admonition:: Calling a management command in your code
``execute()`` should not be called directly from your code to execute a
command. Use :ref:`call_command <call-command>` instead.
.. method:: BaseCommand.handle(*args, **options)
The actual logic of the command. Subclasses must implement this method.
.. method:: BaseCommand.validate(app=None, display_num_errors=False)
Validates the given app, raising :class:`CommandError` for any errors.
If ``app`` is None, then all installed apps are validated.
.. _ref-basecommand-subclasses:
BaseCommand subclasses
---------------------.. class:: AppCommand
A management command which takes one or more installed application
names as arguments, and does something with each of them.
Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement
:meth:`~AppCommand.handle_app`, which will be called once for each application.
.. method:: AppCommand.handle_app(app, **options)
Perform the command's actions for ``app``, which will be the
Python module corresponding to an application name given on
the command line.
.. class:: LabelCommand
A management command which takes one or more arbitrary arguments