Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bennylope/dj-geocoding
Django helpers for simplified geocoding (with Geocodio)
https://github.com/bennylope/dj-geocoding
Last synced: 29 days ago
JSON representation
Django helpers for simplified geocoding (with Geocodio)
- Host: GitHub
- URL: https://github.com/bennylope/dj-geocoding
- Owner: bennylope
- License: bsd-3-clause
- Created: 2014-08-20T02:37:18.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2022-12-26T19:45:22.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T23:47:42.819Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
Awesome Lists containing this project
README
============
dj-geocoding
============.. image:: https://travis-ci.org/bennylope/dj-geocoding.svg?branch=master
:target: https://travis-ci.org/bennylope/dj-geocodingDjango features for simple geocoding. Current support for the Geocodio geocoding service
Read the full docs on `Read the Docs `_.
Installing
==========Install dj-geocoding::
pip install dj-geocoding
Then use it in a project::
import dj-geocoding
Add your geocoding service API credentials to your `settings.py` file::
GEOCODIO_API_KEY="SOMEAPIKEY"
Model
=====Use the optional model mixin to your model if you aren't using PostGIS::
from dj_geocoding.models import GeoBase
class MyModel(GeoBase, models.Model):
passThis adds the followng fields::
latitude = models.DecimalField(decimal_places=15, max_digits=18, null=True,
blank=True)
longitude = models.DecimalField(decimal_places=15, max_digits=18, null=True,
blank=True)Adds a geocode method::
def geocode(self, \*args, \**kwargs):
return geocode()You should extend this in your model, providing the field(s) from which the
address will be pulled::def geocode(self):
return super(MyModel, self).geocode('address')You can choose the separator for providing a single address, too::
def geocode(self):
return super(MyModel, self).geocode('street_address', 'city', 'state',
seperator=", ")And additional property attributes for the `point` attribute.
Bulk geocoding
==============The `bulk_geocode` function takes a queryset and geocodes its member objects.
.. note::
The model *must* implement a point-type field that behaves like a
Point field.Example::
geocoded_qs = bulk_geocode(MyModel.objects.all())
Specifying the field name::
geocoded_qs = bulk_geocode(MyModel.objects.all(), field='point')
Manager
-------The manager class implements a subclassed `QuerySet` with a `geocode` method::
MyModel.objects.all().geocode()
This returns a queryset of the objects updated (or not) that fit within the
limits of the geocoding service. It is a convenient interface tot he
`bulk_geocode` function.Admin site
==========The `GeocodedFilter` filter can be used to filter locations in the admin based
on whether they have been geolocated or not.The `GeolocateMixin` class can be added to your `ModelAdmin` definition to add
the `geocode_address` admin action. This adds the "geocode address" action to
the admin actions dropdown menu and then will allow you to geocode an entire
queryset from the admin.