amisadmin / fastapi-amis-admin

FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.
http://docs.amis.work
Apache License 2.0
964 stars 142 forks source link

Setup id at runtime? #149

Closed MatsiukMykola closed 6 months ago

MatsiukMykola commented 6 months ago

educate event system in amis, but this require id, I do:

class TriggerAdminPage(admin.ModelAdmin):
.
.
.

    async def get_form_item(
        self, request: Request, modelfield: ModelField, action: CrudEnum
    ) -> Union[FormItem, SchemaNode, None]:
        item = await super().get_form_item(request, modelfield, action)

        if item.name == Trigger.event.key:  # noqa
            item.id = item.name # just field name

but why just not assign a name at runtime? are there any reasons?

amisadmin commented 6 months ago

I can not determine the specific reason, you can set a program breakpoint here to debug, see whether the code is running normally.

MatsiukMykola commented 6 months ago

i tried add some event logic, and this requires to set 'id' property for fields because that used to identify field. If not setup id when copypaste to editor online (to educate logic and properties) editor autogenerate id. So I little confuse id require or not?

    async def get_form_item(
        self, request: Request, modelfield: ModelField, action: CrudEnum
    ) -> Union[FormItem, SchemaNode, None]:
        item = await super().get_form_item(request, modelfield, action)

        if item.name == Trigger.event.key:  # noqa
            item.id = item.name

        if item.name == Trigger.target.key:  # noqa
            item.id = item.name  # noqa
            item.selectFirst = True  # noqa
            item.clearValueOnHidden = True  # noqa
            item.visibleOn = '${event!="STANDALONE"}'

            item.source = {
                "url": "TriggerAdmin/target_items/list?tet=${event}",
                "sendOn": 'event'
            }

        return item

maybe just autosetup id field at runtime? i newbe, maybe I'm not right, what you think about this ?

amisadmin commented 6 months ago

Are you suggesting that the fastapi-amis-admin source code set an id for form items by default?

MatsiukMykola commented 6 months ago

because when insert to editor id autocreate, example:

"id": "u:57b6fb4bc910",
amisadmin commented 6 months ago

The default id is not generated for two main reasons:

  1. I want the json data to be as concise as possible while the core functions are working properly.
  2. If id is set to name, it is not certain that conflicts will occur if the amis front-end has multiple form components.
MatsiukMykola commented 6 months ago

you're right, I think the demo requires a good extending I will help with this when being possible, I like you library, but so many dark places)))