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

A good day

Building a free law firm website using Github Pages

Counting Moons With “Lunario”

What's the difference between scrum and agile methods/ agile project management

LiveCollections Part 4: A Table of Carousels

Learn Practical Programming: Step 1+

Jarvis 1.2.0 — What’s New & How to Use It

The Present & Future of Banking APIs

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

Django Models Unchained.

Expenses Tracker App using Django and Pandas.

Docker zing a Python Django Web App on Ubuntu

How to Use Selenium Webdriver for Writing Integration Tests for Django Apps