Open bekab95 opened 6 years ago
from flask_admin.contrib.mongoengine import ModelView from flask import flash, redirect
class UserModelView(ModelView): def on_model_change(self, form, model, is_created): if not is_created: original = self.get_one(model.id) # Fetch the original model if original.version != model.version: flash('This document has been modified by another user. Your changes will not be saved.', 'error') return redirect(self.get_url('.index_view'))
model.version += 1 # Increment the version for successful updates
admin.add_view(UserModelView(User))
If I have opened two browser windows of same document with flask admin (mongoengine) window # 1 and window # 2
when I have updated anything in window # 1 and then incorrectly updated window # 2 flask admin will save window # 2 data (not present data)
is this correct ? or flask admin may have check for changes before saving document ?