mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-14 18:58:13 +08:00
add row_attributes and cell_attributes
This commit is contained in:
@ -28,7 +28,10 @@ class AdminResource(Model):
|
||||
page_title = "admin model"
|
||||
filters = [
|
||||
filters.Search(
|
||||
name="username", label="Name", search_mode="contains", placeholder="Search for username"
|
||||
name="username",
|
||||
label="Name",
|
||||
search_mode="contains",
|
||||
placeholder="Search for username",
|
||||
),
|
||||
filters.Date(name="created_at", label="CreatedAt"),
|
||||
]
|
||||
@ -52,6 +55,11 @@ class AdminResource(Model):
|
||||
]
|
||||
can_create = False
|
||||
|
||||
def cell_attributes(self, obj: dict, field: Field) -> dict:
|
||||
if field.name == "id":
|
||||
return {"class": "bg-danger"}
|
||||
return super().cell_attributes(obj, field)
|
||||
|
||||
def get_actions(self) -> List[Action]:
|
||||
return []
|
||||
|
||||
@ -111,6 +119,11 @@ class ConfigResource(Model):
|
||||
),
|
||||
]
|
||||
|
||||
def row_attributes(self, obj: dict) -> dict:
|
||||
if obj.get("status") == enums.Status.on:
|
||||
return {"class": "bg-green text-white"}
|
||||
return super(ConfigResource, self).row_attributes(obj)
|
||||
|
||||
|
||||
@app.register
|
||||
class GithubLink(Link):
|
||||
|
Reference in New Issue
Block a user