pythondjangomanage.py

If multiple Django apps define the same custom management command, which is used?


The docs are silent on this questios. Will the commands be registered in order, with later apps (in settings.INSTALLED_APPS order) overriding previous commands (whether custom from other apps or the built-in Django commands)?


Solution

  • The answer is yes, as of the current 1.7 release.

    See this line in the Django source to see where the logic is implemented: in the order of apps per the settings.INSTALLED_APPS tuple, each app's management commands are added to a dictionary of commands (which was initialized with Django's built-in commands here), with a single slot for any given command name, so that last one added sticks, overriding any previous app's (or Django's built-in) command with the same name; when executing a command (code here), Django uses the dictionary above to decide which command logic to actually use.

    Note I haven't found any documentation of this, so it should technically be considered unofficial behavior.