Skip to main content

View generators

View generators decide what each screen contains: which fields, in which boxes, with which actions.

Without them a resource still gets all four views with every field in a plain stack. Add a generator when a view needs a different set of fields or a real layout.

from habarico import ModelAdmin
from habarico.schema.generators import (
CreateViewSchemaGenerator,
EditViewSchemaGenerator,
ListViewSchemaGenerator,
ShowViewSchemaGenerator,
)

from .models import Product


class ProductAdmin(ModelAdmin):
model = Product
view_schema_generators = [
ListViewSchemaGenerator(),
CreateViewSchemaGenerator(),
EditViewSchemaGenerator(),
ShowViewSchemaGenerator(),
]

Removing a generator removes the view: no schema, no route, no button pointing at it.

Pages​

PageWhat it covers
List view schema generatorsColumns, filters, sorting, row and toolbar actions
Form schema generatorsCreate, edit and show layouts — boxes, tabs, wizards
Action view schema generatorViews for non-CRUD actions
Field descriptor referenceEvery option a Field accepts, and where it lands in the schema
Box referenceEvery box type and its parameters

Permissions come first​

A generator never widens what DRF allows. If the underlying view rejects the request, the schema is not produced and the frontend has nothing to render — which is why hiding a button is never the mechanism that protects an operation.

See also​