Skip to content

makegov/django-genc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-genc

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.

Features

  • Store and manage GENC country codes with their ISO equivalents
  • Custom CountryField that accepts both 2-character and 3-character ISO and 3-character GENC codes
  • Admin interface integration

Installation

  1. Install the package:
pip install django-genc
  1. Add 'django_genc' to your INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'django_genc.apps.GencConfig',
    ...
]
  1. Run migrations:
python manage.py migrate

Usage

Models

from django.db import models
from django_genc.models import CountryField

class MyModel(models.Model):
    country = CountryField()

API

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

CountryCode Model

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')

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

About

A reusable django app to handle GENC codes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages