How it can use datatables/editos with the Django rest framework properly?
How it can use datatables/editos with the Django rest framework properly?
Could someone show me an example code of how I can accomplish this?
We have bought the editor, but there is no example with the Django rest framework.
My concern is the editor provided some data like this:
{"data": [
{
/Actual data/
}],
"action": "create"
}
But Django expects only this, with different Methods (DefaultRouter)
{
/Actual data/
}
My first idea was to manipulate by "to_internal_value", but I am not sure it is the best way.
Could someone please help me?
This question has an accepted answers - jump to answer
Answers
Hi,
Thanks for your message. We don't have a Django server-side library I'm afraid, but I can certainly help with the manipulation of the data that the client-side is sending to the server into something that your framework is expecting.
To do that, we use the
preSubmit
event - e.g.:What that will do is to take the first row being edited (to make sure to limit the UI to single row editing - use the
editSingle
button type) and put its parameters and values at the top level of the object. Just make sure you don't use the field nameaction
(as Editor uses that to tell the server-side what it is doing; create, edit or remove).Equally, for the returned JSON, you may need to use
postSubmit
to modify the data being returned from the server into something more like what Editor is expecting.Allan
I haven't looked at these in detail but here is a Django Datatables Editor framework you can try. This link contains a tutorial of creating your own.
Kevin