pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

Have To Check Data Changes Before Update Document ? #1752

Open bekab95 opened 6 years ago

bekab95 commented 6 years ago

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 ?

ljluestc commented 1 month 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

Register your view

admin.add_view(UserModelView(User))