call_command should allow the first param to be a module
|Core (Management commands)
|Patch needs improvement:
The current API for the call_command function is:
call_command(name, *args, options)
name is a string, args is a list, and options is a dict. So in my tests.py, I have a line of code like:
This works pretty well, but it limits my ability to rename the command. If instead I were able to write:
from my_app.management.commands import my_custom_command
That would mean that my IDE could automatically update this code if I ever renamed the file. (Most IDEs I'm familiar with can do refactoring of module and file names, but fall down if those names are in strings or comments.)
In call_command, a simple test could be made to convert the module to a string if needed, and then run as it does presently. To me, this makes sense as the recommended API for call_command.
If others agree, I think we should treat this in the documentation the same way as we do the initialization of ForeignKey, where you can either write:
my_key = models.ForeignKey('Book')
from my_app.models import Book
my_key = models.ForeignKey(Book)
With the emphasis being on the latter.