Polish region and city data for Django.
This app provides models, admin integration and commands to import region and city data in your database.
The data is pulled from TERYT database (National Official Register of the Territorial Division of the Country). TERYT is maintained by Polish Central Statistical Office (GUS)
- Database contains:
provinces
counties
municipalities
villages
cities
city districts
Installation
Install django-cities-teryt
pip install django-cities-teryt
Or dev version
pip install -e git+git@github.com:lukaszbanasiak/django-cities-teryt.git#egg=cities_teryt
Add cities_teryt to your INSTALLED_APPS
INSTALLED_APPS = (
...
'cities_teryt',
)
Now, run syncdb, it will only create tables for models
./manage.py syncdb
Configuration
Download SIMC and TERC xml files from TERYT website http://www.stat.gov.pl/broker/access/prefile/listPreFiles.jspa and save them to one directory.
Setup in your settings.py full path to above directory
# Default directory is `import` dir in `django-cities-teryt` app directory
CITIES_TERYT_IMPORT_DIR = '/path/to/dir'
Importing data
To populate your database with all TERYT data use command
./manage.py cities_teryt --data all --import
To remove data use command
./manage.py cities_teryt --data all --flush
To operate on specific type of data enumerate them after --data argument
./manage.py cities_teryt --data province, county, municipality --import
./manage.py cities_teryt --data city, village, district --flush
Notice
Data have relations so it’s best to import everything. Data are large and take time to import (there’s no progress display). Verbosity is controlled through LOGGING.
Examples
Get City by name
>>> City.objects.get(name='Swarzędz')
<City: Swarzędz (0971502)>
To get name of Municipality of this City we can use parent method or call directly municipality attrib
>>> City.objects.get(name='Swarzędz').parent
<Municipality: Swarzędz (302116)>
>>> City.objects.get(name='Swarzędz').municipality
<Municipality: Buk (302103)>
>>> Municipality.objects.get(city__name='Swarzędz')
<Municipality: Swarzędz (302116)>
In this way we can get also Province or County
>>> City.objects.get(name='Swarzędz').province
<Province: wielkopolskie (30)>
>>> Province.objects.get(city__name='Swarzędz')
<Province: wielkopolskie (30)>
… or even Districts
>>> c = City.objects.get(name='Swarzędz')
>>> c.district_set.all()
[<District: Nowa Wieś (0971519)>, <District: Zieleniec (0971525)>]
>>> District.objects.filter(city=c)
[<District: Nowa Wieś (0971519)>, <District: Zieleniec (0971525)>]
List all Cities in the same County
>>> County.objects.get(city__name='Swarzędz').city_set.all()
[<City: Buk (0970520)>, <City: Murowana Goślina (0971152)>, <City: Kostrzyn (0970885)>, <City: Mosina (0971057)>, <City: Pobiedziska (0971287)>, <City: Puszczykowo (0971376)>, <City: Kórnik (0970922)>, <City: Swarzędz (0971502)>, <City: Luboń (0970974)>, <City: Stęszew (0971494)>]
Get pretty display name
# Village, Municipality, County, Province
>>> print Village.objects.get(name='Kaczkowo', province__name='wielkopolskie').get_display_name()
Kaczkowo, Rydzyna, leszczyński, wielkopolskie
# `Municipality` and `County` for "Poznań" is the same so we got only `City` and `Province` name
>>> print City.objects.get(name='Poznań').get_display_name()
Poznań, wielkopolskie
Requirements
See requirements.txt
Metadata
Release files for django-cities-teryt 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-cities-teryt-1.0.1.zip | 13.9 kB | Without provenance | Details |
Release files / django-cities-teryt-1.0.1.zip
| Download URL | django-cities-teryt-1.0.1.zip |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cd9ec1fa8474a248ea72c18eb089e7ce59860a1ff8fcd659bf19b964c9d8aad
|
|
BLAKE2b-256 checksum How to use checksums |
385b5d8b7990bb612596630470da6f2782558359497c3468f351281d4bd05f12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-cities-teryt 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.