Welcome to Django OSM Field’s documentation!

Contents:

Django OSM Field

https://badge.fury.io/py/django-osm-field.png

Django OpenStreetMap Field

Features

  • TODO

Installation

Install django-osm-field from PyPI:

$ pip install django-osm-field

Add django-osm-field to your INSTALLED_APPS:

INSTALLED_APPS = (
    # ...
    'osm_field',
    # ...
)

Usage

Model Layer

You only need to add a single model field to your model. django-osm-field will automatically add two additional fields <name>_lat and <name>_lon to the model to store the latitude and longitude:

from django.core.urlresolvers import reverse
from django.db import models

from osm_field.fields import OSMField


class MyModel(models.Model):
    location = OSMField()

Apart from the field location there will also be a field location_lat and a field location_lon.

Form Layer

from django import forms

from .models import MyModel


class MyModelForm(forms.ModelForm):

    class Meta:
        fields = ['location', 'location_lat', 'location_lon']
        model = MyModel

View Layer

from django.views.generic import CreateView

from .forms import MyModelForm
from .models import MyModel


class MyCreateView(CreateView):
    form_class = MyModelForm
    model = MyModel

Template Layer

{% load static from staticfiles %}<!DOCTYPE HTML>
<html>
  <head>
    <title></title>
    <link rel="stylesheet" href="{% static "css/example.css" %}">
    <!-- Either serve jQuery yourself -->
    <link rel="stylesheet" href="{% static "js/vendor/jquery-2.1.0.min.js" %}">
    <!-- or from a CDN -->
    <script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.min.js"></script>
  </head>
  <body>
    {{ form.media }}
    <form action="" method="post">
      {% csrf_token %}
      {{ form.as_p }}
      <input type="submit" value="Save" />
    </form>
  </body>
</html>

Credits

Contributors

None yet. Why not be the first?

History

0.1.4 (2014-06-02)

  • Add minified JavaScript and CSS sources

0.1.3 (2014-05-28)

  • jQuery is not automatically added by the widgets media class anymore

0.1.0 (2014-05-20)

  • First release on PyPI.

Indices and tables