Create 2 nested packages in your application:

  1. management
  2. commands inside of management

And create py file with a name you want for your command.

Example for resave command in main application :


In file create Command class with wanted code in handle method:

from import BaseCommand, CommandError
from main.models import Tip

class Command(BaseCommand):
    help = 'Resaves tips'

    def handle(self, *args, **options):
        # your code here 
        for t in Tip.objects.all():
            self.stdout.write("Resaving tip {}".format(t))

Now you can call

python resave