Open faaizajaz opened 4 years ago
GeoJSONField
is the model fields. You must use GeoJSONFormField
in a form.
class SampleForm(forms.Form):
location = djgeojson.fields.GeoJSONFormField(geom_type='POINT')
Thanks Gagaro, this works and looking at the djgeojson/fields.py
I can see why. It's not immediately obvious to me why this is not required when using forms.ModelForm
. In that case, the PointField
is automatically rendered as a leaflet widget, which is the behavior expected from reading the docs. I guess this has something to do with forms.ModelForm
itself?
Perhaps it would be useful to update the documentation for both the ModelForm
and Form
use cases?
I'm not sure why it would work in some cases.
Feel free to update the docs and do a PR or point where in the doc it is, I'll try to update it when I find some time.
Sure, I will take some time this week to test and update myself.
Hi, and thanks for this fantastic project (and
django-leaflet
).Using the leaflet widget on
modelForms
(where the model has a corresponding geom field, e.g.PointField()
) works as expected, however when usingforms.Form
the behavior is not consistent.The docs say that form widgets are rendered with Leaflet automatically if
django-leaflet
is available, but this does not seem to be the case.Taking a simple example:
class SampleForm(forms.Form): location = djgeojson.fields.PointField()
From the docs, we expect that when this form is rendered, there will be a leaflet widget for the
location
field, which does not seem to work.