Django – Schedule django-admin command using django-chronograph

Previously we talked about setting up some custom command in a Django project.


I would like to run the custom command in a regular interval. I could use Linux cronjob but it’s hard to manage and check the run history. It would be great if i could setup and manage these scheduled commands on the Django web portal.

django-chronograph, written by wnielson, is a Python Package which allows us to schedule any django-admin command through the web interface. It works well with the UTC timezone but if you have set the TIME_ZONE in your Django project, there would be time discrepancy.

For more detail about the bug, you can refer to the Issue #36 – Job doesn’t follow the Django’s TIME_ZONE setting.

Thanks opensource, finally i found the root cause in the source code. Here is the forked repository which could fix the problem. (Pull request)


OK, let’s see how django-chronograph works.

1. The following Python packages are required. Make sure Django >= 1.6.

pip install django python-dateutil pytz
  • Django (1.6.5)
  • python-dateutil (1.5)
  • pytz (2014.4)


2. Also install the forked django-chronograph.

pip install


3. Create a new Django project, since i want to schedule my custom django-admin command, i would just start with the following project.

  • Django – Create custom django-admin command


4. Include the django-chronograph in

# Application definition



5. Also set the Django project TIME_ZONE.

# Internationalization


#TIME_ZONE = 'UTC' # Setting UTC is fine for wnielson/django-chronograph to work
TIME_ZONE = 'Asia/Hong_Kong' # This will cause 8 hours delay for the scheduled job if you use wnielson/django-chronograph

USE_I18N = True

USE_L10N = True

USE_TZ = True


6. Apply new changes on database.

python syncdb


7. Add the Django project cron to crontab.

* * * * * /path/to/your/python/binary /path/to/your/project/ cron
# In my example
#* * * * * /home/vagrant/.pyenv/versions/django-poc/bin/python /vagrant/custom_command/ cron

8. Start the webserver.

python runserver


9. Browse the admin page @ http://[hostname]:8000/admin/ and login with the superuser account which is created during syncdb. There would be the django-chronograph widget on the admin web portal.

10. Add a new job and you can select all available django-admin commands including our custom command hello_world. Set the Frequency such that it will run minutely.

11. You should be able to find your job in the job listing page.

12. The job is running~

13. The above setup works fine with SQLite but if i change to database to PostgreSQL and you have setup more than one django-chronograph jobs, they would not be executed. I am not sure what cause the problem. I guess sth related to the psycopg2 driver as stated in StackOverflow – Forking Django DB connections. Feel free to post me if you have any idea.

If you are using Django <= 1.5, the following notes may help.

  • Don’t install pytz as it breaks django / chronograph.
  • Need to use cronserver as crontab doesn’t work.


Done =)



One thought on “Django – Schedule django-admin command using django-chronograph”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.