Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run custom admin command from view

Tags:

django

I have a custom admin command that emails out reports. It normally runs from a cron job. What I would like to do is add a button to my web app that when clicked will cause the the admin command to run there and then rather than wait for the cron job to call it. How do I do this? Do I have to call out to a command line such as

python manage.py myadmincmd  

or can I invoke the code from within a view? It seems it would be cleaner if I could do this from within a view without needing to break out to the command line.

like image 889
cedric Avatar asked Jun 06 '11 10:06

cedric


1 Answers

You can use call_command:

from django.core.management import call_command call_command('myadmincmd') 
like image 104
Daniel Roseman Avatar answered Oct 02 '22 13:10

Daniel Roseman