Member-only story

4 useful command lines utility in Django

KokaTic
2 min readJan 2, 2021

In this article, I will present you, briefly, some Django’s command lines utility for administrative tasks that can help you a lot in your projects.

During the development cycle, and while implementing functionalities, we need to perform many things manually, and may take a lot of time sometimes; Django propose a convenient way to perform many tasks easily and fastly with simple shortcuts, those shortcuts can be done by command lines directly.

I’ve selected the top 4 command lines that I use the more while developing application, and which I think are the most usable by others also :

I) Removes all data from the database: python3 manage.py flush

Sometimes we need to delete all the data, especially if we want to reset the database after many manipulations, and we have backup of the original data exported using fixtures (See point IV)

II) Create superuser: python3 manage.py createsuperuser

Especially in the first time after creating a project or when we forgot the admin password, we can easily create another admin account.

III) Export/import fixture: python3 manage.py dumpdata/loaddata app > example.json

A very important procedure, to save data and to restore the backup.

IV) Retrieve models from existing database: python3 manage.py inspectdb > models.py

When we start developing a project based on an existing database, or when we bring some new tables from other sources, this command line is so useful to auto generate the models.

Thank you very much for the time that you spent reading this small article, and let’s keep in touch I will provide more interesting subjects soon.

--

--

KokaTic
KokaTic

Written by KokaTic

Software Engineer / Cloud & DevOps Remote Sensing & GIS Specialist Azure Lover !

No responses yet