Geodirectory¶
Django Terralego provides a mixin you can add to your models to enable the geodirectory. Each model will have a geometry field which will be automatically updated to terralego after each save.
-
class
django_terralego.models.
GeoDirectoryMixin
(*args, **kwargs)¶ A model with a corresponding entry in Terralego.
The entry will be updated at every save. You can pass terralego_commit at False to force not updating the entry.
This model is designed to be one-way only. This means that it won’t update from terralego automatically. If you update the entry from somewhere else, you will have to call _update_from_terralego_entry manually.
-
closest
(tags=None)¶ Get the closest entry of this entry.
Parameters: tags – Optional. A list of tags to filter the entries on which the request is made. Returns: An instance of GeoDirectoryMixin if the entry is one, or a dict describing the entry.
-
delete_from_terralego
(set_id_null=True)¶ Delete the entry in terralego
-
save_to_terralego
()¶ Create or update the entry in terralego, adding the model_path to the tags if needed.
-
update_from_terralego_data
(data)¶ Set self.geometry and self.tags with the values in data and cache it.
Parameters: data – the geojson representing the entry
-
update_from_terralego_entry
()¶ Get the terralego entry related to self.terralego_id and update the instance tags and geometry.
-
You can use django-leaflet to add a map widget. For example for the admin site:
from leaflet.admin import LeafletGeoAdmin
class MyModelAdmin(LeafletGeoAdmin):
fields = ('terralego_geometry')
map_width = '500px'