The Forms library ================= *django-geoportail* ships with rich form widgets, on which your users can draw geographic features. The forms library extends Django's built-in library, and switching to django-geoportail's form library is as simple as changing: .. code-block:: python from django import forms to: .. code-block:: python from geoportal import forms All the fields and widgets from django's form library are available, plus a set of geographic fields and widgets. All the geographic widgets require javascript, so you have to make sure your users have it enabled. Like with the template library, you need to load the javascript library each time you render a rich geographic widget in a template. See :ref:`load-js` Fields `````` The following fields are available. Each field correspond to a geographic model field. * PointField * MultiPointField * LineStringField * MultiLineStringField * PolygonField * MultiPolygonField Basic usage ``````````` Suppose you need a simple form to let users enter a name and point to a location on a map. The form can be written as follows. .. code-block:: python from geoportal import forms class LocationForm(forms.Form): name = forms.CharField(max_length=200) location = forms.PointField() When the form is rendered in the template, a map is displayed and the user can draw a point on the map. The drawn feature will be validated as a geographic field and can be saved to the database. Integration with ``ModelForm`` 's ````````````````````````````````` Let's define a model with some geographic fields and generate a ``ModelForm`` for it: .. code-block:: python # models.py from django.contrib.gis.db import models class Location(models.Model): name = models.CharField(max_length=255) point = models.PointField() Unfortunately, it is not possible to automatically generate a rich widget for geographic fields (geodjango already sets the default widget to a ``