Skip to content


There are three kinds of resources, Link,Model and Dropdown, all are inherited from fastapi_admin.resources.Resource.

You should use app.register decorator to register a resource.

All icons define come from and

Link just display a menu with a link.

from import app
from fastapi_admin.resources import Link

class Home(Link):
    label = "Home"
    icon = "fas fa-home"
    url = "/admin"


Field is the object that Model use, which define how a field display and input.

class AdminResource(Model):
    fields = [
        Field(name="email", label="Email", input_=inputs.Email()),
            input_=inputs.Image(null=True, upload=upload),

You can pass str or Field to fields, if is str, it will try to auto mapping display and input widget, such as displays.Boolean for BooleanField, inputs.Date for DateField.

All kind of widgets you can find in Display and Input.


Subclass of Field but for a virtual field, useful if you want to show some computed fields.

class ComputeField(Field):
    async def get_value(self, request: Request, obj: dict):
        return obj.get(

What you need to do is just override the get_value method.

class RestDays(ComputeField):
    async def get_value(self, request: Request, obj: dict):
        days = (obj.get( -
        return days if days >= 0 else 0


The Action define the action display in every end of row, and bulk action for every model.

By default, there are two actions, Which are delete action and edit action, and one bulk action, which allow delete rows in bulk.

To use that, you should override the get_actions and get_bulk_actions. The following example hide all default actions with return empty list.

class AdminResource(Model):
    async def get_actions(self, request: Request) -> List[Action]:
        return []

    async def get_bulk_actions(self, request: Request) -> List[Action]:
        return []


The class that mode.get_toolbar_actions used.

class ToolbarAction(Action):
    class_: Optional[str]


Model is the core resource, which make TortoiseORM model as a menu and display a data table with create, update, and delete.

class AdminResource(Model):
    label = "Admin"
    model = Admin
    page_pre_title = "admin list"
    page_title = "Admin Model"
    filters = [
            placeholder="Search for username",
        filters.Date(name="created_at", label="CreatedAt"),


  • label: The menu name display.
  • fields: The fields want to show and edit.
  • model: TortoiseORM model.
  • page_size: The default page size.
  • page_pre_title: Show page pre title in content.
  • page_title: Show page title in content.
  • filters: Define filters for the model, which will display filter inputs in table above, all kinds of filters you can find in Filter.


You can add extra attributes to each row by use row_attributes.

class ConfigResource(Model):
    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)

The example above will add the css class = "bg-green text-white" for the row which status = enums.Status.on.


You can add extra attributes to each column by use column_attributes.

class LogResource(Model):
    async def column_attributes(self, request: Request, field: Field) -> dict:
        if == "content":
            return {"class": "w-50"}
        return await super().column_attributes(request, field)

The example above will add the css class = "w-50" for the column which content.


Same as row_attributes but for the cell, you can add extra attributes to cell depends on the row object and column field.

class AdminResource(Model):
    async def cell_attributes(self, request: Request, obj: dict, field: Field) -> dict:
        if == "id":
            return {"class": "bg-danger text-white"}
        return await super().cell_attributes(request, obj, field)


Show toolbar actions top right of the table.

class CategoryResource(Model):
    async def get_toolbar_actions(self, request: Request) -> List[ToolbarAction]:
        actions = await super().get_toolbar_actions(request)
        return actions

The dropdown resource just contains Link and Model resource, and which can be nested.

class Content(Dropdown):
    label = "Content"
    icon = "fas fa-bars"
    resources = [ProductResource, CategoryResource]

Last update: August 28, 2022 06:31:41