django-leaflet icon indicating copy to clipboard operation
django-leaflet copied to clipboard

LeafletGeoAdmin should show a map for readonly geometries

Open leplatrem opened this issue 11 years ago • 3 comments

selection_474

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)

leplatrem avatar Oct 29 '14 20:10 leplatrem

:+1:

christophlingg avatar Mar 01 '16 11:03 christophlingg

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.

thomas-fred avatar Dec 07 '21 16:12 thomas-fred

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.

Gagaro avatar Dec 13 '21 09:12 Gagaro