Django Custom Management Command

management/
__init__.py
commands/
__init__.py
your_command_name.py
from django.core.management.base import BaseCommand, CommandErrorfrom django.conf import settingsfrom django.core.management import call_commandimport jsonclass Command(BaseCommand): args = '' help = 'Loads the initial data in to database' def handle(self, *args, **options):
# Your Code
call_command('loaddata', 'peeldb/fixtures/countries.json', verbosity=0)
call_command('loaddata', 'peeldb/fixtures/states.json', verbosity=0)
call_command('loaddata', 'peeldb/fixtures/cities.json', verbosity=0)
call_command('loaddata', 'peeldb/fixtures/skills.json', verbosity=0)
call_command('loaddata', 'peeldb/fixtures/industries.json', verbosity=0)
call_command('loaddata', 'peeldb/fixtures/qualification.json', verbosity=0)
result = {'message': "Successfully Loading initial data"}
return json.dumps(result)

The article was originally published at MicroPyramid blog.

--

--

--

Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Deploy WSO2 API Manager in Kubernetes using Google Cloud Platform

41 — DevOps on Azure

41 — DevOps on Azure

My namespace stuck in Terminating state!!!

Pure CSS Photo Carousel

Exploring GitHub Security Alerts

Watch Star Wars in CLI

Swapping Nodes in a Linked List — Day 96(Python)

Golang development for Raspberry Pi 3. Getting started

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
MicroPyramid

MicroPyramid

Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company

More from Medium

Docker zing a Python Django Web App on Ubuntu

Introduction to Django Framework

introduction to Django Framework

How to Configure Django/PostgreSQL Environment Using Docker

User Auth with REST API in Django — Part 2