A reusable Django app for working with GENC (Geopolitical Entities, Names, and Codes) country codes. Source data comes from the NGA site and the CIA World Fact Book.
- Store and manage GENC country codes with their ISO equivalents
- Custom
CountryFieldthat accepts both 2-character and 3-character ISO and 3-character GENC codes - Admin interface integration
- Install the package:
pip install django-genc- Add 'django_genc' to your INSTALLED_APPS:
INSTALLED_APPS = [
...
'django_genc.apps.GencConfig',
...
]- Run migrations:
python manage.py migratefrom django.db import models
from django_genc.models import CountryField
class MyModel(models.Model):
country = CountryField()A custom field that can handle both 2-digit ISO and 3-digit GENC codes.
from django_genc.models import CountryField
class MyModel(models.Model):
country = CountryField()The field will:
- Store values as 3-digit GENC codes in the database
- Accept both 2-digit ISO and 3-digit GENC codes as input
- Automatically convert ISO codes to GENC codes
- Validate that the code exists in the database
The base model for storing country codes:
from django_genc.models import CountryCode
# Get a country by GENC code
country = CountryCode.objects.get(genc_code='USA')
# Get a country by ISO code
country = CountryCode.objects.get(iso_code='US')
# Look up a country by a code under either standard
country = CountryCode.objects.get_by_code('US')Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.