| 24 | |
| 25 | @app.register |
| 26 | class AdminResource(Model): |
| 27 | label = "Admin" |
| 28 | model = Admin |
| 29 | icon = "fas fa-user" |
| 30 | page_pre_title = "admin list" |
| 31 | page_title = "admin model" |
| 32 | filters = [ |
| 33 | filters.Search( |
| 34 | name="username", |
| 35 | label="Name", |
| 36 | search_mode="contains", |
| 37 | placeholder="Search for username", |
| 38 | ), |
| 39 | filters.Date(name="created_at", label="CreatedAt"), |
| 40 | ] |
| 41 | fields = [ |
| 42 | "id", |
| 43 | "username", |
| 44 | Field( |
| 45 | name="password", |
| 46 | label="Password", |
| 47 | display=displays.InputOnly(), |
| 48 | input_=inputs.Password(), |
| 49 | ), |
| 50 | Field(name="email", label="Email", input_=inputs.Email()), |
| 51 | Field( |
| 52 | name="avatar", |
| 53 | label="Avatar", |
| 54 | display=displays.Image(width="40"), |
| 55 | input_=inputs.Image(null=True, upload=upload), |
| 56 | ), |
| 57 | "created_at", |
| 58 | ] |
| 59 | |
| 60 | async def get_toolbar_actions(self, request: Request) -> List[ToolbarAction]: |
| 61 | return [] |
| 62 | |
| 63 | async def cell_attributes(self, request: Request, obj: dict, field: Field) -> dict: |
| 64 | if field.name == "id": |
| 65 | return {"class": "bg-danger text-white"} |
| 66 | return await super().cell_attributes(request, obj, field) |
| 67 | |
| 68 | async def get_actions(self, request: Request) -> List[Action]: |
| 69 | return [] |
| 70 | |
| 71 | async def get_bulk_actions(self, request: Request) -> List[Action]: |
| 72 | return [] |
| 73 | |
| 74 | |
| 75 | @app.register |