Django Global Places is a simple Django app to provide a model for global places.
Project description
Django-GlobalPlaces
Plug and play configurations and data for countries, states and cities from all over the globe.
Requirements
- Django >= 3.8 *
- Python >= 3.8 *
- Django Rest Framework >= 3.13 *
- This requirement is only necessary if you are using the provided REST endpoints.
- django-filter >= 23.0 *
- This requirement is only necessary if you are using the provided REST endpoints.
(*) Not tested with earlier versions.
Quick Setup
Install package
pip install django-global-places
Add django_global_places
app to INSTALLED_APPS in your django settings.py:
INSTALLED_APPS = (
...,
"django.contrib.staticfiles",
'django_global_places'
'rest_framework', # required only if using the provided REST endpoints
...,
)
(Optional) Include viewset routes
from django_global_places.urls import router as django_global_places_router
your_router.registry.extend(django_global_places_router.registry)
Explanation
This library handles the configuration and creation of Countries
, States
, and Cities
.
After installation, you need to specify three parameters in your settings.py
file:
INCLUDE_LOCATION
: Enables the creation of the models.LOCATION_SCOPE
: Determines the scope of models required ('countries', 'states', or 'cities').INCLUDE_EXPANDED_COUNTRY
: Incorporates additional fields into the Country model.
Example:
GLOBAL_PLACES = {
"INCLUDE_LOCATION": True,
"LOCATION_SCOPE": "state",
"INCLUDE_EXPANDED_COUNTRY": False,
}
Once these variables are configured, your next steps are to run makemigrations
and migrate
.
To populate the newly created models, you should execute a Django command. This command will create all the necessary objects and update them if they already exist.
python manage.py populate_global_places
Rest endpoints
Three viewsets are included, one for each model: Country
, State
, and City
. Each viewset features:
A list view displaying a summary of the objects. A detail view presenting comprehensive information about each object.
-
CountryViewSet:
- url: global-places/countries
- search fields:
name
andiso3
- ordering fields:
id
,name
andiso3
-
StateViewSet:
- url: global-places/states
- search fields:
name
andstate_code
- ordering fields:
id
,name
andstate_code
- filtering fields:
country
-
CityViewSet:
- url: global-places/cities
- search fields:
name
- ordering fields:
id
andname
- filtering fields:
state
,state__country
Full examples here in Postman collection.
Acknowledgements
Special thanks to the Countries States Cities Database for providing the JSON files used for populating the data.
Contributing
Maintained and developed by Linkchar Software Development.
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
File details
Details for the file django_global_places-0.8.3.tar.gz
.
File metadata
- Download URL: django_global_places-0.8.3.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48b81c9d78b0e2021fdb84230f4b2373a01f67d2928388ccf5ab72e5ff4f32f6 |
|
MD5 | 0c534f2ad7e88a3dc8cf681786eaaea9 |
|
BLAKE2b-256 | d10dcc032ae018d09cf0e9b7e907dd2b0e6feee64fef0b4b3c799e34e9d35d5a |
File details
Details for the file django_global_places-0.8.3-py3-none-any.whl
.
File metadata
- Download URL: django_global_places-0.8.3-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69544a8e21521c1d26f1866177b97bec9765c62e5b286a0d06903bed3295db8 |
|
MD5 | af7a180936a5ab1c9be8af351a60e723 |
|
BLAKE2b-256 | 0dbb8a75936c1747b43813d6e962c63644c30d04426121078591a22db762e5e4 |