Kintarō
Kintarō

Reputation: 3177

How to run a series of manage.py commands in Django?

I have a Django project. Everytime I deploy, I need to run a series of manage.py command (such as syncdb, south migiration, fixture update).

I am getting tired of type the command line by line and therefore I wrote a python script to do these:

import subprocess
subprocess.call(['python', 'manage.py', 'syncdb'])
#Skip the detail
subprocess.call(['python', 'manage.py', 'loaddata', 'setup/fixture.xml'])

I am wondering if there is a better way to do this?

Thanks.

Upvotes: 4

Views: 2790

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174624

You can use fabric, a Python library that allows you to script remote actions. This question has some links in the accepted answer for more information on fabric and django.

You can also call management commands directly:

from django.core.management import call_command

call_command('syncdb')
call_command('loaddata', 'setup/fixture.xml')

Save that as a normal python file and execute it from your shell or as part of your deployment scripts.

Upvotes: 7

Related Questions