Giter Club home page Giter Club logo

Comments (6)

mmmcorpsvit avatar mmmcorpsvit commented on June 3, 2024

i think, Request must contain all fields and request data

from fastapi-amis-admin.

prostospirit avatar prostospirit commented on June 3, 2024

I experimented a bit and realized that it is possible to override ModelAction.get_action

It will looks like a

   async def get_action(self, request: Request, **kwargs) -> Action:
        action = await super().get_action(request, **kwargs)
        node: AmisNode = getattr(action, action.actionType, None)
        if node:
            node.body = Service(
                schemaApi=AmisAPI(
                    method="post",
        >>>>>       url=self.router_path + self.page_path + "?item_id=${IF(promoaction_ids, promoaction_ids, promoaction_id)}",  # override default PK name
                    responseData={
                        "&": "${body}",
                        "api.url": "${body.api.url}?item_id=${api.query.item_id}",
                        "initApi.url": "${body.initApi.url}?item_id=${api.query.item_id}" if self.form_init else None,
                        "submitText": "",
                    },
                )
            )
        return action

and it will works correctly, but I think this should be provided by the functionality or there should be a more friendly interface for this

from fastapi-amis-admin.

mmmcorpsvit avatar mmmcorpsvit commented on June 3, 2024

you can set

class CarCategoryAdmin(admin.ModelAdmin):
    page_schema = PageSchema(label="Car Category", icon="fa fa-truck")
    model = CarCategory

    pk_name: str = "id" # no ?

from fastapi-amis-admin.

prostospirit avatar prostospirit commented on June 3, 2024

@mmmcorpsvit no, it doesn't work correctly for me to perform actions on records. If I set only pk_name, then item_id is empty when I make request for action from admin to backend.

the meaning is that I want to use the first key's name other than id

from fastapi-amis-admin.

amisadmin avatar amisadmin commented on June 3, 2024

I'm not sure if this will work, but you can try the idea of defining a virtual id foreign key.

from sqlmodelx import SQLModel
from sqlmodel import Field
from sqlalchemy import column_property
from fastapi_amis_admin import admin

class Promoaction(SQLModel, table=True):
    __tablename__ = "promoaction"

    promoaction_id: int
    name: str

class Promoaction2(Promoaction, table=True):
    id: int = Field(
        None,
        title="Read-only primary key",
        sa_column=column_property(Promoaction.promoaction_id),
    )
    
class ActionAdmin(admin.ModelAdmin):
    page_schema = 'Promoaction Management'
    model = Promoaction2

from fastapi-amis-admin.

prostospirit avatar prostospirit commented on June 3, 2024

@amisadmin

can try the idea of defining a virtual id foreign key.

I checked but it didn't work.

Traceback:

Traceback (most recent call last):
  File "/home/sergei/.pycharm_helpers/pydev/pydevd.py", line 1534, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sergei/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "..../admin_backend/main.py", line 19, in <module>
    site.mount_app(app)
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1536, in mount_app
    self.register_router()
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1402, in register_router
    self._register_admin_router_all()
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1394, in _register_admin_router_all
    admin.register_router()
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1400, in register_router
    self._create_admin_instance_all()
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1386, in _create_admin_instance_all
    [self.get_admin_or_create(admin_cls) for admin_cls in self._registered.keys()]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 1361, in get_admin_or_create
    admin = admin_cls(self)
            ^^^^^^^^^^^^^^^
  File "..../python3.12/site-packages/fastapi_amis_admin/admin/admin.py", line 646, in __init__
    SqlalchemyCrud.__init__(self, self.model, self.engine)
  File "..../python3.12/site-packages/fastapi_amis_admin/crud/_sqlalchemy.py", line 265, in __init__
    SqlalchemySelector.__init__(self, model, fields)
  File "..../python3.12/site-packages/fastapi_amis_admin/crud/_sqlalchemy.py", line 124, in __init__
    assert self.fields, "fields is None"
AssertionError: fields is None

from fastapi-amis-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.