Updated the AppCommand API to support apps without a models module.

This commit is contained in:
Aymeric Augustin 2013-12-24 23:43:47 +01:00
parent aff57793b4
commit bb8ec71f61
4 changed files with 63 additions and 27 deletions

View file

@ -313,17 +313,34 @@ BaseCommand subclasses
.. class:: AppCommand
A management command which takes one or more installed application
names as arguments, and does something with each of them.
A management command which takes one or more installed application labels 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.
Rather than implementing :meth:`~BaseCommand.handle`, subclasses must
implement :meth:`~AppCommand.handle_app_config`, which will be called once for
each application.
.. method:: AppCommand.handle_app(app, **options)
.. method:: AppCommand.handle_app_config(app_config, **options)
Perform the command's actions for ``app``, which will be the
Python module corresponding to an application name given on
the command line.
Perform the command's actions for ``app_config``, which will be an
:class:`~django.apps.AppConfig` instance corresponding to an application
label given on the command line.
.. versionchanged:: 1.7
Previously, :class:`AppCommand` subclasses had to implement
``handle_app(app, **options)`` where ``app`` was a models module. The new
API makes it possible to handle applications without a models module. The
fastest way to migrate is as follows::
def handle_app_config(app_config, **options):
if app_config.models_module is None:
return # Or raise an exception.
app = app_config.models_module
# Copy the implementation of handle_app(app_config, **options) here.
However, you may be able to simplify the implementation by using directly
the attributes of ``app_config``.
.. class:: LabelCommand