Skip to main content

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 and iso3
    • ordering fields: id, name and iso3
  • StateViewSet:

    • url: global-places/states
    • search fields: name and state_code
    • ordering fields: id, name and state_code
    • filtering fields: country
  • CityViewSet:

    • url: global-places/cities
    • search fields: name
    • ordering fields: id and name
    • 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


Download files

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

Source Distribution

django_global_places-0.8.7.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

django_global_places-0.8.7-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file django_global_places-0.8.7.tar.gz.

File metadata

  • Download URL: django_global_places-0.8.7.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.7

File hashes

Hashes for django_global_places-0.8.7.tar.gz
Algorithm Hash digest
SHA256 3b7d08011f6f4a26235a8aff7b069fe1948d287976fbd066c9e38f75b74f42cf
MD5 dadb6ac20bd0534a3b4904d9f049d7d4
BLAKE2b-256 2f51c15890763e967cce9d777b745444b9f109fa32edc98ab908be6269110fa1

See more details on using hashes here.

File details

Details for the file django_global_places-0.8.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_global_places-0.8.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6f40ee13e01f8e705ec54130feb9d1a7d71d9ca7dcdccf10124406849f05ab26
MD5 d2ca75359740f931c4b1c61e34fc87a4
BLAKE2b-256 4387fbe39aae1725aa08e568d3a0f5ca682c5dc834a200212e617f004b429c0d

See more details on using hashes here.

Supported by

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