ModelView generator #460
iagobalmeida
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hey, |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there!
I've been working on a module that automates the integration between SQLAlchemy, the SQLAdmin and FastAPI CrudRouter. The main concept of the module is to generate the admin page and an API from a single table file.
So, I needed to be able to create a
ModelView
using only aSQLAlchemy ORM Model
instance. To achieve that, I used aditional keys when defining the table and also acolumn.info
class in order to be able to define the behaviour of eachColumn
. Then, thegenerate_admin_model_view
reads all that info and returns aModelView
child class.For example, this is the definition of a table:
The
sidebar_category
key is not necessary, I use it to define where the sidebar menu should be grouped. The solution to achieve this is pretty simple, by using the{% for group in admin.views | groupby('sidebar_category') %}
filter.The generator uses both the information defined in the
Post #Admin config
section and the informations contained in theColumnInfo
of each column to define the parameters used to create aModelView
instance:There's a lot of space for improvement, but I really enjoy the ideia of generating the
ModelView
instances using only the table model definition.I'm open to suggestions and really curious to know if this is usefull for other devs.
Beta Was this translation helpful? Give feedback.
All reactions