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.
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
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.
Include the leaflet_admin_list
application into the INSTALLED_APPS
list, like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'leaflet',
'leaflet_admin_list',
...
]
In your admin.py:
...
from leaflet.admin import LeafletGeoAdminMixin
from leaflet_admin_list.admin import LeafletAdminListMixin
...
class WaypointAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, ModelAdmin):
...
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.
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:
field
identifies the geometry field shownapp_label
andmodel_name
identify the model of the instance shownpk
is 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:
popup
if 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 methodtooltip
if 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_style
if present, is used to apply as anoptions
parameter when creating lines and polygons, see also Leaflet Path optionspoint_style
if present, is used as anoptions
parameter to create a Leaflet marker, see also Marker options- an
icon
member of thepoint_style
if present, is used as anoptions
parameter 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 GeoJSONFeatureList
instance representing aqueryset
get_geojson_features(request, o, queryset)
returns thefeatures
member of theFeatureList
instance for the model instanceo
get_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 GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_geometry(request, name, o, queryset)
returns ageometry
member of the GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_properties(request, name, o, queryset)
returns aproperties
member of the GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_feature_popup(request, name, o, queryset)
returns apopup
property of the GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_feature_tooltip(request, name, o, queryset)
returns atooltip
property of the GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_feature_verbose_name(request, name, o, queryset)
returns a verbose name of the instanceo
geometry fieldname
which is used to create popup and tooltipget_geojson_feature_line_style(request, name, o, queryset)
returns aline_style
property of the GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_feature_point_style(request, name, o, queryset)
returns apoint_style
property of the GeoJSONFeature
instance representing the instanceo
geometry fieldname
get_geojson_feature_icon_style(request, name, o, queryset)
returns anicon
member of thepoint_style
property of the GeoJSONFeature
instance representing the instanceo
geometry fieldname