Skip to content
caramelcookbook · 0.16.0
Browse documentation
Cookbook / Data and forms

Create a resource.

Generate a book catalog, then make the model, actions, views, and request specs your own.

Proved by scripts/check frappe-projectTarget: 0.16.0
ContractValue
NeedsA configured application
You will haveA Book model, changeset, migration, actions, views, routes and request spec
StatusRun end to end by scripts/check frappe-project, from frappe new to the passing spec; the options below are proved by the generator’s own specs
Proved byfrappe check · frappe corretto spec/requests/books_spec.cr

Where the change goes

app/models/book.crThe stored shape
app/changesets/book.crRules for writes
db/migrations/Creates the table
app/actions/books.crShared form helpers
app/actions/books/Request handling
app/views/books/Browser presentation
config/routes.crSeven routes, inserted
config/paths.crPath helpers, inserted
spec/requests/books_spec.crBehavior checks

Decide before you generate

Two choices change what the generator writes. Make them first.

  • A multi-tenant application The resource belongs to the tenant unless you pass --central. Set up multi-tenancy →
  • A translated application Run frappe make locale CODE before resource generation. Frappé then adds typed message calls and default catalog entries. Set up internationalization →

Generate the feature

Run inside a configured application. Review the generated files and migration before applying it.

  1. Generate the resource
    Terminal · inside the application
    frappe make resource Book title:string author:string

    Expect: Prints Generated PATH for each of the 19 files it writes or edits: the seven actions and app/actions/books.cr, the five views, the model, the changeset, db/migrations/…_create_books.cr, config/routes.cr, config/paths.cr and spec/requests/books_spec.cr, then Run frappe migrate to apply the new schema. Use frappe routes to see the generated URLs.

  2. Apply the reviewed migration
    Terminal · inside the application
    frappe migrate

    Expect: Prints Applied 1 migrations., then The database matches the declared schema.

Choose the generated surface

PassTo get
original_url:string:urlURL validation, a URL input, and valid request-spec samples
--only=create,showA smaller resource; create and show are required, and edit needs new and update
--plural=peopleAn irregular plural for the table, the routes and the module
:serverA field the action sets
:uniqueA unique index and constraint checks

The field types are string, int32, int64, bool, float64 and time, each nullable with ?. Read the make resource syntax →

Extend the generated spec with your own validation rule and an example that fails that rule.

Prove it

Prove the behavior

Terminal · inside the application
frappe check
frappe corretto spec/requests/books_spec.cr

Passing: frappe check exits 0, and frappe corretto runs the generated request spec, which creates, reads, updates and deletes a book and refuses a forged token and an unknown field, then ends with Corretto: 1 of 1 workers passed.

Proved Run end to end by a check.

scripts/check frappe-project creates an application, generates this resource and two more, migrates, and runs frappe check, frappe lint and frappe corretto on the result.