Awesome Open Source
Awesome Open Source

django-places

A Django app for store places with autocomplete function and a related map to the selected place.

Badges

PyPI Travis-ci Codacy Badge

Quickstart

Install dj-places and add it to your installed apps:

$ pip install dj-places

INSTALLED_APPS = (
	...
	'places',
	...
)

Add the following settings and maps api key ( read more here ):

PLACES_MAPS_API_KEY='YourAwesomeUltraSecretKey'
PLACES_MAP_WIDGET_HEIGHT=480
PLACES_MAP_OPTIONS='{"center": { "lat": 38.971584, "lng": -95.235072 }, "zoom": 10}'
PLACES_MARKER_OPTIONS='{"draggable": true}'

Then use it in a project:

from django.db import models
from places.fields import PlacesField


class MyLocationModel(models.Model):
    location = PlacesField()

This enables the following API:

    >>> from myapp.models import ModelName
    >>> poi = ModelName.objects.get(id=1)
    >>> poi.position
    Place('Metrocentro, Managua, Nicaragua', 52.522906, 13.41156)
    >>> poi.position.place
    'Metrocentro, Managua, Nicaragua'
    >>> poi.position.latitude
    52.522906
    >>> poi.position.longitude
    13.41156

For using outside the Django Admin:

<form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Save">
    {{ form.media }}
</form>

Remember to add the {{ form.media }} in your template.

Demo

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements_test.txt
(myenv) $ python runtests.py

Credits

Tools used in rendering this package:

Similar Projects


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (55,531
django (1,053
autocomplete (182
geolocation (103
google-maps (84
cookiecutter (51