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 :

12a7ba35.png

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

from django.core.management.base 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))
            t.save()

Now you can call

python manage.py resave