https://github.com/makegov/django-genc
A reusable django app to handle GENC codes
https://github.com/makegov/django-genc
Last synced: 8 months ago
JSON representation
A reusable django app to handle GENC codes
- Host: GitHub
- URL: https://github.com/makegov/django-genc
- Owner: makegov
- License: apache-2.0
- Created: 2025-05-01T21:20:12.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-13T23:10:31.000Z (about 1 year ago)
- Last Synced: 2025-10-04T03:58:42.686Z (8 months ago)
- Language: Python
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-genc
A reusable Django app for working with GENC (Geopolitical Entities, Names, and Codes) country codes. Source data comes from the [NGA site](https://nsgreg.nga.mil/registries/browse/results.jsp?registryType=genc®isterField=IE4&itemTypeField=ggp&gce=all&field=name&show=all&status=all&sort=nameasc) and the [CIA World Fact Book](https://www.cia.gov/the-world-factbook/references/country-data-codes/).
## 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:
```bash
pip install django-genc
```
2. Add 'django_genc' to your INSTALLED_APPS:
```python
INSTALLED_APPS = [
...
'django_genc.apps.GencConfig',
...
]
```
3. Run migrations:
```bash
python manage.py migrate
```
## Usage
### Models
```python
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.
```python
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:
```python
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.