I'm trying to have a directory structure for my custom django-admin commands.
According to the Django tutorial, commands are created as modules under the management/commands directory.
e.g.
management/commands/closepoll.py
I have many commands so I'm trying to split them into packages. I want to have a package structure, like:
management/commands/closepoll/closepoll.py <-- contains the Command class.
management/commands/closepoll/closepoll_utils.py
management/commands/closepoll/__init__.py
Tried that, but Django does not recognize the command.
It is not possible since Django only searches the commands directory as we can see from the source code [GitHub]:
What you can do is that you can have the
Commandclass in the "commands" directory and the the other parts of the same can be in a package:In case of the above example
closepoll.pywill have theCommandclass and what you had inclosepoll_utils.pywill be inclosepoll_utils/__init__.py. In fact you can even have theCommandclass in your package and simply import it inclosepoll.py.