Skip to main content

Module model_admin

Module model_admin 

Source
Expand description

Generic model-admin — a ModelViewSet-style CRUD admin for arbitrary #[derive(Model)] types, rendered inside the CMS admin chrome.

The framework’s own ListView/ViewSet can’t inject the CMS’s async, DB-backed add_chrome, so they can’t back a chrome’d admin screen. This is a CMS-native path: a host registers a model with register_model_admin!, which captures the model’s rustango::core::ModelSchema + a type-erased “list rows as JSON” thunk, and the admin serves a chrome’d index at /cms-admin/model/<slug> driven by the model’s list_display.

It ships the registry + the read-only, paged index. Create / edit / delete (generic forms from FieldSchema) + filter / search / order are not implemented yet.

Structs§

ModelAdmin
One registered model admin.

Functions§

find
The model admin registered under slug, if any.
list_columns
The index columns as (field_name, header_label) pairs. Uses the model’s admin(list_display = …) when set; otherwise falls back to the display field, else the first few scalar fields — so a model with no admin hints still renders something useful.
registered
Every registered model admin, sorted by slug.
row_cell
Render one row’s value for column col as a display string. Strings pass through; null / missing → empty; everything else → its compact JSON (numbers, bools, nested objects).

Type Aliases§

ListRowsFn
Type-erased “fetch one page of the model’s rows as JSON” — the index data source. Called with (pool, limit, offset); returns that window in primary-key order plus the total row count. Built by register_model_admin! from the concrete model’s objects() (a derive-generated inherent method, so it can’t be reached generically — hence the thunk).