Run custom admin command from view

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.


You can use call_command:

from django.core.management import call_command
call_command('myadmincmd')