I have a Django management commands that I would like to run. I would like to have it available for a user by clicking the button and it would execute it. I do not need help to write one - I have them working, but always I need to run them from the terminal like:
heroku run python manage.py syncdata
Very convenient would be to just click the button on the running production website and it would start it for me. How can I make this happen on the site running on Heroku?
As a simple example:
from django.core.management.base import BaseCommand
from project.models import Video
class Command(BaseCommand):
help = 'Sync Movie / Plays'
def handle(self, *args, **options):
uri_video = Video.objects.all()
for item in uri_video:
item.update(title=item.title.capitalize())
print "Done."
It is just updating the title which not important.
handle()function of your management command is nothing else than a python function that you can call from anywhere. So just build a view that calls it and your button could have a javascript calling that view using ajax, returning if it succeeded or not.