Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

370
Views
How to store long dictionary in Django using postgresql

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.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!