Question

I'm creating a Django/JQuery/MySQL application where I pass a composite data structure 'grid' as

return render_to_response('products.html', grid)

I render 'grid' into a set of UI elements ('td', 'button', 'div' etc. encapsulated in a HTML 'table'.

A typical use case:

  1. User clicks on a certain UI element in the table
  2. jQUery.click() is called which creates a inner 'input' tag for the clicked element.
  3. User can add/modify/delete text from the element.
  4. When focus is lost, jQuery.blur() is called which reverts the original properties of the clicked element such as removing input tag etc.
  5. jQuery.blur() also calls a AJAX function where I do a .post call to send in user modified data back to a URL (function in view).
  6. The called function in view then commits the new changes in database and returns a 'success' event back to web page:

    tc_model_instance.update(tc_id=json_data['id'])
    

Through this use case, as you can see the changes are immediately committed to the database as soon as user eneters data and gives up focus on a particular element. Without using DB transactions in INNODB, how do I go about creating a View-Template association such that any changes in HTML template are asynchronously reflected in the model, but not necessarily written into the database.

A related question: If possible I'd also like to create a event based bi-directional association between rendered template and my data structures as part of the view in such a way that any changes made either in web browser's UI element or associated view's data are always in sync. I plan to use AJAX for the most purpose. Not sure if forms would make sense in this regard.

Thanks.

Was it helpful?

Solution

You could probably throw a copy of the object into the session map and all posts alter that object instead of the DB directly. Then when the user presses a save button you'd fire off another POST command to the server that would then just call session['my_object'].save().

Note though that the session object is also saved in the DB, so if you are trying to avoid hitting the DB totally what I wrote above wouldn't help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top