1

I have several custom command classes that subclass BaseCommand. I use those in a specific order to populate the DB.

I want to write another command to combine those in a single one. I don't want to write a shell script that will execute the commands in the right order. I want it to be a django-admin command.

I know I can just throw the code of all commands in a single one but I am looking for a more generic way to do it. So that I will have all the population scripts per db table clean and separated.

1 Answer 1

3

You could write another command, and use call_command for each command you want to run.

from django.core import management

Then in your management command:

management.call_command('my_first_command')
management.call_command('my_second_command')
...

If your management commands take args or kwargs you'll need to do a bit more work.

Sign up to request clarification or add additional context in comments.

2 Comments

You are right, it's in the documentation, I should have seen it. Do you think I should remove the question?
No, don't delete the question. The question is fine, somebody else might find it useful in future. If we removed all questions that were covered by the docs, there wouldn't be many left!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.