Comments (6)
i think, Request must contain all fields and request data
from fastapi-amis-admin.
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.
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.
@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.
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.
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)
- Code Editor not follow Locale settings (and how add support Jinja syntax support?) HOT 1
- ➜ andy pip install fastapi_amis_admin[cli] zsh: no matches found: fastapi_amis_admin[cli] HOT 1
- 如何自定义某个search_fields字段的UI组件 HOT 3
- Setup id at runtime? HOT 6
- Passing primary_key is not supported when also passing a sa_column HOT 1
- Using the Simple CRUD Example, Article Creation is not Persisted HOT 3
- can not create data from foreign key HOT 1
- 如何通过点击跳转到新页面? HOT 1
- 如何将ModelAdmin注册到PageAdmin中作为页面的一部分 HOT 1
- qq群还在吗,申请没人同意 HOT 2
- 启动报错AttributeError: secondary
- class BaseApiOut(GenericModel, Generic[_T], BaseApiSchema):TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
- 如何动态切换多语言
- S3 support
- SqlAlchemy model with UUID column does not work properly
- KeyError: 'id'. self.pk: InstrumentedAttribute = self.model.__dict__[self.pk_name]
- The filter on input-group does not work
- "AttributeError: 'AdminSite' object has no attribute 'AnnotatedItemIdList'."
- JSONB, post raise exception
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-amis-admin.