如何注册仅存在于单元测试中的自定义Django管理命令?
在Django 1.5中,您可以这样做:
app.directive('contenteditable', [function() {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelController
link: function(scope, element, attrs, ngModel) {
if (!ngModel) {return;} // do nothing if no ng-model
ngModel.$render = function() {
element.html(ngModel.$viewValue);
};
element.on('blur keyup change', function() {
scope.$evalAsync(read);
});
ngModel.$render();
function read() {
var html = element.html();
// When we clear the content editable the browser leaves a <br> behind
// If strip-br attribute is provided then we strip this out
if ( attrs.stripBr && html == '<br>' ) {
html = '';
}
ngModel.$setViewValue(html);
}
}
};
}]);
但是,在Django 1.8中,from django.test import TestCase
from django.core.management import _commands
from myapp.testse.commands import MyTestCommand
class JobTestCase(TestCase):
fixtures = ['test_jobs.json']
def setUp(self):
# Install the test command; this little trick installs the command
# so that we can refer to it by name
_commands['test_command'] = MyTestCommand()
不再存在。查看代码,现在看来这些是通过django.core.management.get_commands动态检索的,但我没有看到添加或注册任意命令类的方法。这可能吗?