Expand description
A generic admin editor for a host app’s own models.
#[derive(CmsAdmin)] on a #[derive(Model)] type implements
CmsAdmin from the struct’s #[cms_admin(...)] and #[field(...)]
attributes and registers a CmsAdminPage for it. The page lives
at /cms-admin/x/<slug> inside the admin chrome and gives editors:
- a list with search, the chosen columns and pagination;
- add and edit forms built from the
#[field]widgets (every widget the page editor has, media and page choosers included); - delete, with a confirmation.
Access runs through the role matrix: the model gets a row with view,
add, edit and delete columns (<resource>.view … .delete), and the
dispatcher checks the matching codename on every request.
CmsAdminOverrides holds the hooks a real app needs: fields that
cannot be edited, records that cannot be created or deleted,
validation, side effects after a save or before a delete, options for
a select, and extra widgets for relations the struct has no column
for (a many-to-many list).
Structs§
- CmsAdmin
Meta - Static description of one model’s editor, built by the derive.
- CmsAdmin
Page - The admin page serving model
T.#[derive(CmsAdmin)]registers it; register it by hand withregister_admin_page!(CmsAdminPage<T>)only when implementingCmsAdminyourself. - Field
Error - A validation failure for one field, or for the whole form when
fieldis"_form".
Traits§
- CmsAdmin
- What
#[derive(CmsAdmin)]implements. Host code rarely calls these directly;CmsAdminPagedoes. - CmsAdmin
Overrides - Hooks for a model’s editor. Every method has a default, so
impl CmsAdminOverrides for MyModel {}is enough to start.
Functions§
- delete_
record - Delete
rowafterCmsAdminOverrides::can_deleteandCmsAdminOverrides::before_delete.Ok(false)whencan_deleterefuses. - save_
record - Apply a posted form to
rowand store it, running the hooks in order:CmsAdmin::admin_apply(skippingCmsAdminOverrides::read_only_fields),CmsAdminOverrides::validate, the save,CmsAdminOverrides::save_extra, thenCmsAdminOverrides::after_save. A row without a primary key is added, and only whenCmsAdminOverrides::can_createallows it. - section_
from - Parse a
sectionattribute value:content,siteandsettingsare the built-in sections; anything else names a new one.