Skip to content

Base view

Bases: BaseModelView

Base class for defining admnistrative views for the model.

Usage
from sqladmin import BaseView, expose

class CustomAdmin(BaseView):
    name = "Custom Page"
    icon = "fa-solid fa-chart-line"

    @expose("/custom", methods=["GET"])
    async def test_page(self, request: Request):
        return await self.templates.TemplateResponse(request, "custom.html")

admin.add_base_view(CustomAdmin)
Source code in sqladmin/models.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
class BaseView(BaseModelView):
    """Base class for defining admnistrative views for the model.

    ???+ usage
        ```python
        from sqladmin import BaseView, expose

        class CustomAdmin(BaseView):
            name = "Custom Page"
            icon = "fa-solid fa-chart-line"

            @expose("/custom", methods=["GET"])
            async def test_page(self, request: Request):
                return await self.templates.TemplateResponse(request, "custom.html")

        admin.add_base_view(CustomAdmin)
        ```
    """

    # Internals
    is_model: ClassVar[bool] = False
    templates: ClassVar[Jinja2Templates]
    _admin_ref: ClassVar["BaseAdmin"]

    name: ClassVar[str] = ""
    """Name of the view to be displayed."""

    identity: ClassVar[str] = ""
    """Same as name but it will be used for URL of the endpoints."""

    methods: ClassVar[List[str]] = ["GET"]
    """List of method names for the endpoint.
    By default it's set to `["GET"]` only.
    """

    include_in_schema: ClassVar[bool] = True
    """Control whether this endpoint
    should be included in the schema.
    """

    icon: ClassVar[str] = ""
    """Display icon for ModelAdmin in the sidebar.
    Currently only supports FontAwesome and Tabler icons.
    """

    category: ClassVar[str] = ""
    """Category name to group views together."""

    category_icon: ClassVar[str] = ""
    """Display icon for category in the sidebar."""

name = '' class-attribute

Name of the view to be displayed.

identity = '' class-attribute

Same as name but it will be used for URL of the endpoints.

methods = ['GET'] class-attribute

List of method names for the endpoint. By default it's set to ["GET"] only.

icon = '' class-attribute

Display icon for ModelAdmin in the sidebar. Currently only supports FontAwesome and Tabler icons.

include_in_schema = True class-attribute

Control whether this endpoint should be included in the schema.