Skip to main content

A django app for working with GENC country codes

Project description

django-genc

A reusable Django app for working with GENC (Geopolitical Entities, Names, and Codes) country codes.

Source data comes from the CIA World Fact Book: https://www.cia.gov/the-world-factbook/references/country-data-codes/ https://nsgreg.nga.mil/registries/browse/results.jsp?registryType=genc&registerField=IE4&itemTypeField=ggp&gce=all&field=name&show=all&status=all&sort=nameasc

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
  • REST API serialization support
  • Admin interface integration
  • Data loading from CSV

Installation

  1. Install the package:
pip install django-genc
  1. Add 'genc' to your INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'genc',
    ...
]
  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()

Serializers

from rest_framework import serializers
from django_genc.serializers import CountryFieldSerializer

class MyModelSerializer(serializers.ModelSerializer):
    country = CountryFieldSerializer()
    
    class Meta:
        model = MyModel
        fields = ['country']

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_genc-0.1.0.tar.gz (40.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_genc-0.1.0-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file django_genc-0.1.0.tar.gz.

File metadata

  • Download URL: django_genc-0.1.0.tar.gz
  • Upload date:
  • Size: 40.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.0

File hashes

Hashes for django_genc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3db5a2607c8999d446b976b0cb1d54f01066f76f413ec3187379c4bb0875cee
MD5 4ddffe9ad536d2673a991b2cede18580
BLAKE2b-256 181744a83bbbcc213929d8e389753b6b27bd1623e3b83bb64afb782880daa09a

See more details on using hashes here.

File details

Details for the file django_genc-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_genc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f61dff4b3c9768d503b9e614d99aa5fe8a62ddf15ac44c0e83bbf5c117581c26
MD5 caa830572ec28504991784776103cd9f
BLAKE2b-256 04220624184faa277a42e8997f8d418b89f3a83196e50bede507cd45c50295ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page