django-leaflet-admin-list
django-leaflet-admin-list copied to clipboard
The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango.
Django Leaflet Admin List

The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango. It requires a django-leaflet package.
Installation
Stable version from the PyPi package repository
pip install django-leaflet-admin-list
Last development version from the GitHub source version control system
pip install git+git://github.com/nnseva/django-leaflet-admin-list.git
Compatibility notice for libgdal
Use proper versions of libgdal library with older Django versions.
Some strange effect of reverting coordinates in the GeoJSON (not concerning to the package, but regarding to the Django itself) has been found with the modern libgdal version (2.9) and the following Django versions: 2.0, 2.1, 2.2, 3.0
Downgrade libgdal to the libgdal26 (present in the Ubuntu apt repository) if you would like to use such Django versions.
The source of the effect is backward incompatibility of libGDAL, the issue here describes the problem.
Configuration
Include the leaflet_admin_list application into the INSTALLED_APPS list, like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'leaflet',
'leaflet_admin_list',
...
]
Using
In your admin.py:
...
from leaflet.admin import LeafletGeoAdminMixin
from leaflet_admin_list.admin import LeafletAdminListMixin
...
class WaypointAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, ModelAdmin):
...
Visual View
Open the admin list view and see the map above the list of objects. Every object in the list is represented on the map.
Also, the bounding box filter is added to the list of filters.
Use a bounding box filter to filter objects by the geometry. Just press the 'Current map bounding box' link to filter out
objects outside of the current map bounding box. The current filtering box will be represented on the map as a rectangle. The color
of the rectangle is shown to the right of the 'Current map bounding box' link. Manual input of the bounding_box parameter
in the address box also works.
As usual, pressing the filter or paging link will reload a page with new parameters. The map keeps its position for standard static Django filters and pager using permalink.
Customizing view
The geodata shown on the map is represented as GeoJSON feature collection. Every GeoJSON feature corresponds to one geo field of one Django model instance. All standard Django geometry-based fields are shown on the map by default. Every such feature has the following list of mandatory properties to be used:
fieldidentifies the geometry field shownapp_labelandmodel_nameidentify the model of the instance shownpkis an instance primary key which identifies the model instance shown
The following optional GeoJSON feature properties are used to customize the look and feel of the feature on the map:
popupif present, is used to create a popup. A value started with '<' is used to create an HTML popup, else the text popup is used, see also bindPopup methodtooltipif present, is used to create a tooltip. A value started with '<' is used to create an HTML tooltip, else the text tooltip is used, see also bindTooltip methodline_styleif present, is used to apply as anoptionsparameter when creating lines and polygons, see also Leaflet Path optionspoint_styleif present, is used as anoptionsparameter to create a Leaflet marker, see also Marker options- an
iconmember of thepoint_styleif present, is used as anoptionsparameter to create a Leaflet icon, see also Icon options
The Admin class may override every part of this data, or even the whole data output overriding admin methods producing this data:
get_geojson_feature_list(request, queryset)returns the whole GeoJSONFeatureListinstance representing aquerysetget_geojson_features(request, o, queryset)returns thefeaturesmember of theFeatureListinstance for the model instanceoget_geojson_geometry_fields(request, o, queryset)returns a list of geometry field names that need to be included in the feature listget_geojson_feature(request, name, o, queryset)returns a GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_geometry(request, name, o, queryset)returns ageometrymember of the GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_properties(request, name, o, queryset)returns apropertiesmember of the GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_feature_popup(request, name, o, queryset)returns apopupproperty of the GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_feature_tooltip(request, name, o, queryset)returns atooltipproperty of the GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_feature_verbose_name(request, name, o, queryset)returns a verbose name of the instanceogeometry fieldnamewhich is used to create popup and tooltipget_geojson_feature_line_style(request, name, o, queryset)returns aline_styleproperty of the GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_feature_point_style(request, name, o, queryset)returns apoint_styleproperty of the GeoJSONFeatureinstance representing the instanceogeometry fieldnameget_geojson_feature_icon_style(request, name, o, queryset)returns aniconmember of thepoint_styleproperty of the GeoJSONFeatureinstance representing the instanceogeometry fieldname