Django: partition management commands in subfolders

The Django management command documentation shows all the commands created in the app / management / commands folder. Can I enter commands into subfolders such as app / management / commands / install and app / management / commands / maintenance? How to do it?

+5
source share
1 answer

Unfortunately, with Django 1.4, there seems to be no way to do this. Sources for django.core.management.__init__.pyhave this method:

def find_commands(management_dir):
    """
    Given a path to a management directory, returns a list of all the command
    names that are available.

    Returns an empty list if no commands are defined.
    """
    command_dir = os.path.join(management_dir, 'commands')
    try:
        return [f[:-3] for f in os.listdir(command_dir)
                if not f.startswith('_') and f.endswith('.py')]
    except OSError:
       return []

, commands, . , " " - , , , Command, :

def load_command_class(app_name, name):
    """
    Given a command name and an application name, returns the Command
    class instance. All errors raised by the import process
    (ImportError, AttributeError) are allowed to propagate.
    """
    module = import_module('%s.management.commands.%s' % (app_name, name))
    return module.Command()

, subfolder.command, script .

, , . , "namespace'd" , - , , - (, _). , , ...

+5
source

All Articles