Skip to content

Field not in the DB #200

Answered by jowilf
dfioravanti asked this question in Q&A
May 30, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

you can create a custom field and override the parse_obj function.

Example:

class MyCustomField(BooleanField):

    async def parse_obj(self, request: Request, obj: Any) -> Any:
        return 'active' in obj.name

then you can define your field list like this:

fields = ['id', 'name', MyCustomField('status', exclude_from_create=True, exclude_from_edit=True)]

Full example -> https://github.com/jowilf/starlette-admin-demo/blob/ad82fde9acf7dbd5a2cf58d51ec2e3db61451ba6/app/sqla/fields.py#L24

For more information -> https://jowilf.github.io/starlette-admin/advanced/custom-field/

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dfioravanti
Comment options

Answer selected by dfioravanti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants