title: Django Model load choices from a json file
body: <p>I am writing a Django <code>User</code> model which contains a <code>mobile_country_code</code> field. This field needs to be populated from a list of ISD codes, pre-populated in a json file. What is the best pythonic way to do the same?  </p>
  
  <p>My current implementation, which is working:</p>
  
  <p><code>json_data/countries.json</code></p>
  
  <pre><code>[
      ...
      {
          "name": "Malaysia",
          "dial_code": "+60",
          "code": "MY"
      },
      ...
  ]
  </code></pre>
  
  <p><code>project/app/models.py</code></p>
  
  <pre><code>import json, os
  
  class User(models.Model):
      with open(os.path.dirname(__file__)+'/json_data/countries.json') as f:
          countries_json = json.load(f)
          COUNTRIES_ISD_CODES = [(str(country["dial_code"]), str(country["name"])) for country in countries_json]
  
      mobile_country_code = models.CharField(choices=COUNTRIES_ISD_CODES, help_text="Country ISD code loaded from JSON file")
  </code></pre>
  
  <p>Other Possible options listed below. Which one is better to use?</p>
  
  <ul>
  <li>Using a model's <code>__init__</code> method to create <code>COUNTRIES_ISD_CODES</code></li>
  <li><p>Importing a library method, like:</p>
  
  <pre><code>from library import import_countries_isd_codes
  
  class User(models.Model):
      mobile_country_code = models.CharField(choices=import_countries_isd_codes())
  </code></pre></li>
  </ul>