I tried to subclass the default LeafletWidget with a custom geometry_field_class.
If you need a reusable customization of widgets maps, first override the JavaScript field behaviour by extending L.GeometryField, then in Django subclass the LeafletWidget to specify the custom geometry_field_class.
from django import forms
from leaflet.forms.widgets import LeafletWidget
from .models import POI
class GeocodingWidget(LeafletWidget):
geometry_field_class = 'GeocodingField'
template_name = 'asdf.html'
class POIForm(forms.ModelForm):
class Meta:
model = POI
fields = ('geom',)
widgets = {'geom': GeocodingWidget()}
class Media:
js = ('leaflet.js',)
As you see, I've even tried to set a different template. When I inspect the map widget in the backend, I don't see my custom GeocodingField used. I'm using latest Django 1.9.
The widget needs to be set on the AdminModel as well. It isn't a good design though, your way should work without having to do that (as it keeps from using several widgets as well..).
I tried to subclass the default
LeafletWidget
with a customgeometry_field_class
.my forms.py
As you see, I've even tried to set a different template. When I inspect the map widget in the backend, I don't see my custom
GeocodingField
used. I'm using latest Django 1.9.