Import All Country Languages Using Django Management Command

Md Mahmudul Huq Topu
2 min readMay 31, 2022

--

Today, we are gonna create a simple django management command to import 185 languages with iso code which can be used for many use cases.
We will import from a json file containing the following information structure

[
{
"code": "bn",
"name": “Bengali",
"native": "বাংলা"
}
]

For example your model can be like this

class AllLanguages(TimeStamp):
name = models.CharField(max_length=50)
status = models.BooleanField(default=False)
meta = models.JSONField(blank=True, null=True)
def __str__(self):
return str(self.name)

Now create a management command at apps/someapp/management/commands/language.py

Note: We need to create two folders/directories management and commands and both directories must have an empty __init__.py file to work as module.
Also put the languages.json file into the commands directory
[Download the languages.json file here]

Now copy and paste the following code into language.py file

Now just run python manage.py language and the data will be populated on the database.

language model in admin

If you go to admin, you can see all languages. I kept it simple but we should put error handling logic also. Now we can make APIs or anything with it.

Next I will show to import All Countries, States and Cities using one command. Follow me on medium to get more! A clap always inspires

--

--

Md Mahmudul Huq Topu
Md Mahmudul Huq Topu

Written by Md Mahmudul Huq Topu

I’m a Full Stack Software Engineer at Skill Jobs.Also do youtubing(Metacentric Bangladesh) since 2014.

No responses yet