-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Actions: custom PK (except id) is not passed to ModelAction.handle() #165
Comments
i think, Request must contain all fields and request data |
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 |
you can set class CarCategoryAdmin(admin.ModelAdmin):
page_schema = PageSchema(label="Car Category", icon="fa fa-truck")
model = CarCategory
pk_name: str = "id" # no ? |
@mmmcorpsvit no, it doesn't work correctly for me to perform actions on records. If I set only the meaning is that I want to use the first key's name other than |
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 |
I checked but it didn't work. Traceback:
|
For example, I have the following model:
I have the next admin:
and i have the next action:
I expected that item_id would be passed to the handle function in the item_id parameter, but it does not arrive.
Same time in the browser console I see the following request:
http://...:8000/admin/my_app/PromoactionAdmin/LoadMailsByAction/api?item_id= (item_id is empty)
What needs to be done for this to work correctly? I tried to find this configuration settings but failed. Thanks in advance for your answer and for the project!
The text was updated successfully, but these errors were encountered: