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®isterField=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
CountryFieldthat 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
- Install the package:
pip install django-genc
- Add 'genc' to your INSTALLED_APPS:
INSTALLED_APPS = [
...
'genc',
...
]
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3db5a2607c8999d446b976b0cb1d54f01066f76f413ec3187379c4bb0875cee
|
|
| MD5 |
4ddffe9ad536d2673a991b2cede18580
|
|
| BLAKE2b-256 |
181744a83bbbcc213929d8e389753b6b27bd1623e3b83bb64afb782880daa09a
|
File details
Details for the file django_genc-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_genc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 51.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f61dff4b3c9768d503b9e614d99aa5fe8a62ddf15ac44c0e83bbf5c117581c26
|
|
| MD5 |
caa830572ec28504991784776103cd9f
|
|
| BLAKE2b-256 |
04220624184faa277a42e8997f8d418b89f3a83196e50bede507cd45c50295ce
|