The Django management commands documentation shows all commands being created in an app/management/commands folder. Is it possible to put commands into subfolders, like app/management/commands/install and app/management/commands/maintenance? How would this be done?
The Django management commands documentation shows all commands being created in an app/management/commands folder.
Share
Unfortunatly, as of Django 1.4 there seems to be no way of doing that. The sources for
django.core.management.__init__.pyhave this method:As you can see, it only considers files directly inside the
commandsfolder, ignoring any subfolders. However, if you "monkey patch" this function somehow, the rest of the code should work fine, since the code that actually creates theCommandinstance is this:So, if you had a command named
subfolder.commandit would load the right script and instantiate the right class.From a practical standpoint, however, I see no use of doing that. Sure, having "namespace’d" commands would be nice, but you can always prefix all your commands with some name if you want, using something else as a separator (such as
_). The command name length – and the number of keystrokes needed to type them in the terminal – will be the same…