Creating custom management commands
Django management commands help us interact with the Django framework seamlessly. A lot of tedious tasks such as migration, getting build files, and more become streamlined if we use Django management commands. Django provides a lot of management commands out of the box and can be found in the documentation: https://docs.djangoproject.com/en/stable/ref/django-admin/.
In this section, we are going to learn how to create custom management commands in Django. In Django, each application can register its custom actions with manage.py
. To create a new management command, we need to create a simple file structure inside the Django app. In the given Django app, we need to create the management/commands
directory structure, as shown in Figure 4.10. Any file that’s created in the commands
folder is registered as a Django management command, except if the name of the file begins with an underscore (_
).
In the example shown in Figure 4.10, we have...