-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_view_ext.py
37 lines (29 loc) · 1.13 KB
/
admin_view_ext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask_admin.contrib.sqla import ModelView
from flask import flash
from safrs import ValidationError
from sqlalchemy.orm.base import instance_state
from admin.admin_model_converter_ext import AdminModelConverterExt
class AdminViewExt(ModelView):
"""
Quick example on adding additional SQLAlchemy types via AdminModelConverterExt
"""
model_form_converter = AdminModelConverterExt
def __init_(self, **kwargs):
super().__init__(self, **kwargs)
''' def on_model_change(self, form, model, is_created):
if is_created:
model.id = '''
"""
Enable SAFRSBase support Flask-admin does not create regular Instances
"""
def build_new_instance(self):
model = self._manager.new_instance()
model.__init__() # <-- Call SAFRSBase.__init__()
state = instance_state(model)
self._manager.dispatch.init(state, [], {})
return model
def handle_view_exception(self, exc):
if isinstance(exc, ValidationError):
flash(message=exc.message, category='error')
return True
return super(self).handle_view_exception(exc)