class ConfigResource(Model): label = "Config" model = Config icon = "fas fa-cogs" filters = [ filters.Enum(enum=enums.Status, name="status", label="Status"), filters.Search(name="key", label="Key", search_mode="equal"), ] fields = [ "id", "label", "key", "value", Field( name="status", label="Status", input_=inputs.RadioEnum(enums.Status, default=enums.Status.on), ), ] async def row_attributes(self, request: Request, obj: dict) -> dict: if obj.get("status") == enums.Status.on: return {"class": "bg-green text-white"} return await super().row_attributes(request, obj) async def get_actions(self, request: Request) -> List[Action]: actions = await super().get_actions(request) switch_status = Action( label="Switch Status", icon="ti ti-toggle-left", name="switch_status", method=Method.PUT, ) actions.append(switch_status) return actions
class ProductResource(Model): label = "Product" model = Product filters = [ filters.Enum(enum=enums.ProductType, name="type", label="ProductType"), filters.Datetime(name="created_at", label="CreatedAt"), ] fields = [ "id", "name", "view_num", "sort", "is_reviewed", "type", Field(name="image", label="Image", display=displays.Image(width="40")), "body", "created_at", ]
class ConfigResource(Model): label = "Config" model = Config icon = "fas fa-cogs" filters = [ filters.Enum(enum=enums.Status, name="status", label="Status"), filters.Search(name="key", label="Key", search_mode="equal"), ] fields = [ "id", "label", "key", "value", Field( name="status", label="Status", input_=inputs.RadioEnum(enums.Status, default=enums.Status.on), ), ] async def row_attributes(self, request: Request, obj: dict) -> dict: if obj.get("status") == enums.Status.on: return {"class": "bg-green text-white"} return await super().row_attributes(request, obj)