How to Write Management commands In Python/Django Applicaton


First we need to create project as well as app

Inside the app >  we write the management commands.

>Project
   >Project
   >App
      >managements
          >commands
              >__init__.py
             >FIlename.py

          >__init__.py
      >migrations
          >__init__.py
          >views.py
          >models.py

Inside the Filename.py we write the code. as per the below strutuer.

from django.core.management.base import BaseCommand

def add():
  pass

def sum():
  pass
class Command(BaseCommand):
    help = “Cammand to load data”
    def handle(self, *args, **kwargs):
       add()
       sum()
       more……

To run this code we need to edit the configurations.

LEAVE A REPLY

Please enter your comment!
Please enter your name here