I am working on a feature for an application of mine that allows users to edit certain configurations that is stored in a database. These configurations are shared and not unique to one user, but obviously only a select few would have permission to edit it.
Using a TemplateView
the client can view this data that gets nicely populated into a DataTable
with inline editing that updates live as the user edits it. Issue I am now experiencing is as follows, if two or more users are logged in and trying to edit this config
at the same time there is a clash between what the two are seeing. One could have edited row 2 while the other has edited row 10 and not know about 2 being changed unless they refresh the page. Worse, they could both be editing the same line and not know it. Is there a built in method to “lock” editing to one user at a time? I looked into select_for_update()
but I don’t think this is the correct solution.
Any tips or best practices are welcomed since I am struggling to figure the best way of doing it. Currently I am just using another table to keep track of when someone starts an edit “session” and block the other user from being able to do anything till the one is done but what if that user closes the browser without exiting the session. It blocks the other user then.