Open dagostinelli opened 2 years ago
@dagostinelli This package is meant to be used with ORMs (hence the term ModelView
). It could probably be customized to utilize an API, but you would need to override a lot of functions. And, if you're using FastAPI why opt for a package built with flask? There is a package that essentially mimics the same thing as this one, but written for FastAPI (https://github.com/fastapi-admin/fastapi-admin).
@mrjoes vetoed (can be closed)
Here is a small example to use flask admin role based authorization and expose json api
class ViewWithMethodViews(flask_admin.BaseView):
def is_accessible(self):
return (current_user.is_active and
current_user.is_authenticated and
current_user.has_role('config')
)
@flask_admin.expose('/')
def index(self):
return "Hello World for /"
@flask_admin.expose_plugview('/_api/1')
class API_v1(MethodView):
def get(self, cls):
return jsonify({"Hello": "world", "method": "GET", "url": "/_ap1/1"})
def post(self, cls):
return jsonify({"Hello": "world", "method": "POST", "url": "/_ap1/1"})
admin.add_view(ViewWithMethodViews())
All of the examples are using some form of ORM (or files). My use-case is a json API made with FastAPI. How about an API example?