I have one form and one formset in my django project. The form has one input with a Point geometry. So I have input there which looks something like that:
39.237103, 25.667217
when user sends a form I want to split this input and save this as Point geometry, in models Point looks like this:
position = gismodels.PointField(null=True, srid=4326)
I use this code for validation and saving form, formset and Point geometry
if request.method == "POST":
checklist_form = ChecklistForm(request.POST)
observation_formset = ObservationFormSet(request.POST)
#error
if checklist_form.is_valid() and observation_formset.is_valid():
checklist = checklist_form.save(commit=False)
latitude, longitude = request.POST.get('position', '').split(', ', 1)
checklist.position = Point(longitude, latitude)
checklist.save()
for observation_form in observation_formset:
observation = observation_form.save(commit=False)
observation.checklist_id = checklist
observation.save()
But the problem is that POST data for position has bad format so validation of checklist_form raise this error before I can split the coordinates:
String or unicode input unrecognized as WKT EWKT, and HEXEWKB.
I read that I can copy POST data and change them, but I also read it is a bad practice. What I think about is using javascript for changing coordinates for appropriate format but GeoDjango surely has better functionality for saving Point geometry.
Here is a simple field for entering or editing
Point
s using django: