I am trying to add list of airport codes and their name in Django postgresql database using models. My target is that airport name shows up when someone types airport code like you see of airlines' websites. I have made a dictionary like this
airports = {"JFK": 'New York',
"AAE": 'Annabah',
"AAF": 'Apalachicola',
"AAG": 'Arapoti',
"AAH": 'Aachen',
"AAI": 'Arraias',
"AAJ": 'Awaradam'
"...": '........'
}
So when someone types JFK code, the airport name New York will show up. I understand I'll have to use ajax and jquery for that. But first I have to save the dictionary of hundreds of airports in my postgresql database. Any help what is the best way to save this dictionary and I dont want to type them by hand one by one because they are hundreds.
You should use JSONField, it will allow for nested dictionaries inside your models.
Example
from django.contrib.postgres.fields import JSONField
from django.db import models
class Dog(models.Model):
name = models.CharField(max_length=200)
data = JSONField()
def __str__(self): # __unicode__ on Python 2
return self.name
Source: https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/fields/#querying-jsonfield