django-leaflet
django-leaflet copied to clipboard
LeafletGeoAdmin should show a map for readonly geometries

from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin
from geotrek.zoning import models as zoning_mode
class ReadOnlyGeom(LeafletGeoAdmin):
readonly_fields = ('geom',)
admin.site.register(zoning_models.City, ReadOnlyGeom)
:+1:
Can anyone give me a clue on how to achieve this? It seems related to my problem: I'm trying to display the results on the reverse side of a FK, so a related manager's worth of geometry fields.
I did something similar for JSON field, I guess the same logic can be used to display a map:
class MapModelAdmin(admin.ModelAdmin):
[...]
@property
def media(self):
js = ["leaflet.min.js", "js/my_readonly_script.js"] # Whatever scripts you need
css = {"all": ["leaflet.min.css", "css/my_readonly_script.css"]} # Whatever sheets you need
return super(MapModelAdmin, self).media + forms.Media(js=js, css=css)
Then you can change how the fields are displayed in JS.