0

I'm creating a web mapping application using Django and Leaflet application that allows users to create and edit features.

The creation of a new feature was easy to implement. After a new feature is drawn on the map, a bootstrap modal with a django form rendered directly from my template automatically appeared. The user fills the form and send this form to a django view using an ajax call.

But I can't figure out, how to edit an existing feature. More precisely, I don't know how to display a form (from an ajax call) pre-filled with the data already saved in my database.

Here is the workflow :

1) When the user select an existing feature, a popup is opened where the previous information are displayed

2) On the bottom of the popup an edit link allow to edit the existing information

3) When the user click on this link, I query my django's view with an ajax call to get all the information related to this object

4) The result is sent to the user interface (json, new htmlform...) and a new edit form is automatically displayed

The first three steps work fine but I don't know how to deal with the last one (4). From your point of view, what is the best approach ?

I don't want to reload my page to display the edit form, I really want to stay on the same page. Do you have any good idea how I can do this ?

Thanks for your help.

1
  • Essentially, you just need to use Javascript clientside. I'd use JSON in the response, and parse it clientside via Javascript, using that to update the displayed page.
    – jvc26
    Oct 21, 2014 at 12:05

1 Answer 1

0

Forms in django are basically html (try printing one in console). You can create an object form in your view and send it back to the client in a json or something (as string) and then just print it. You would need to have it styled already to do it this way.

def ajax_post(self, request):
    form = MyFormClass(object_to_edit)
    return HttpResponse(form, content_type = "application/text")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.