Skip to content
djust/docs
Appearance
Mode
djust.org →
Browse documentation

3 min read

Scaffolding Generator

Generate a complete CRUD LiveView from a model name and field definitions.

Quick Start

python manage.py djust_gen_live blog Post title:string body:text published:boolean

This creates:

FileDescription
blog/views.pyPostListView with mount, search, show, create, update, delete handlers
blog/urls.pyURL routing using live_session()
blog/templates/blog/post_list.htmlList + detail panel with dj-* directives
blog/tests.pyBasic test scaffold

Usage

python manage.py djust_gen_live <app_name> <ModelName> [field:type ...] [options]

Arguments

ArgumentDescription
app_nameDjango app name (directory must exist)
model_namePascalCase model name (e.g. Post, BlogPost)
fieldsField definitions as name:type pairs

Options

OptionDescription
--dry-runPreview files without writing
--forceOverwrite existing files
--no-testsSkip generating test file
--apiGenerate JSON API (render_json) instead of HTML

Supported Field Types

TypeDjango Model FieldForm Input
stringCharField<input type="text">
textTextField<textarea>
integerIntegerField<input type="number">
floatFloatField<input type="number" step="any">
decimalDecimalField<input type="number" step="0.01">
booleanBooleanField<input type="checkbox">
dateDateField<input type="date">
datetimeDateTimeField<input type="datetime-local">
emailEmailField<input type="email">
urlURLField<input type="url">
slugSlugField<input type="text">
fk:ModelForeignKey<input type="number"> (ID)

Examples

Basic CRUD

python manage.py djust_gen_live blog Post title:string body:text

With Foreign Key

python manage.py djust_gen_live blog Post title:string body:text author:fk:User

Preview Without Writing

python manage.py djust_gen_live blog Post title:string --dry-run

JSON API Mode

python manage.py djust_gen_live blog Post title:string body:text --api

Overwrite Existing

python manage.py djust_gen_live blog Post title:string --force

Generated Code Patterns

Views

The generated view uses standard djust patterns:

  • mount() initializes state
  • _compute() re-queries the database
  • @event_handler() decorates all event handlers
  • Search uses Q objects for OR logic across text fields
  • CRUD operations: create, show, update, delete

URLs

Routes use live_session() for proper WebSocket support:

from djust.routing import live_session

urlpatterns = [
    *live_session("/blog", [
        path("post/", PostListView.as_view(), name="post_list"),
    ]),
]

Templates

Generated templates use djust directives:

  • dj-root / dj-view for LiveView binding
  • dj-input for real-time search
  • dj-click / dj-submit for event handlers
  • dj-value-* for passing parameters
  • dj-confirm for delete confirmation
  • dj-loading for loading states

After Generation

  1. Add your app to INSTALLED_APPS
  2. Add 'yourapp.views' to LIVEVIEW_ALLOWED_MODULES
  3. Include yourapp.urls in your root URL conf
  4. Create the model in yourapp/models.py
  5. Run python manage.py makemigrations && python manage.py migrate

Project & app scaffolding (djust new, startproject, startapp)

Beyond per-model CRUD generation, the djust CLI ships with three commands for bootstrapping projects and apps end-to-end (added in v0.3.0):

# Modern entrypoint (recommended) — feature flags select what to wire
python -m djust new myapp

# Pre-canned feature combos via flags
python -m djust new myapp --with-auth --with-db --with-presence --with-streaming

# Generate from a YAML schema describing your models
python -m djust new myapp --from-schema schema.yml

# Legacy entrypoints (still supported)
python -m djust startproject myproject
python -m djust startapp myapp

djust new

djust new <name> creates a full Django project layout pre-configured for djust:

What you getDefaultToggled by
Django project + initial appalways
LIVEVIEW_CONFIG settings stubalways
WebSocket routing wired into asgi.pyalways
Auth + login/logout LiveViewsoff--with-auth
Postgres LISTEN/NOTIFY wiringoff--with-db
PresenceMixin exampleoff--with-presence
Stream-friendly base templatesoff--with-streaming
Models generated from a schema fileoff--from-schema schema.yml

The --from-schema mode reads a small YAML file describing models + fields and generates models, admin, migrations, LiveViews, and templates in one step — handy for spike projects.

startproject / startapp

The legacy commands mirror Django's vanilla django-admin startproject / startapp but add djust's defaults (LIVEVIEW_CONFIG, LIVEVIEW_ALLOWED_MODULES, LiveSessionMiddleware, the WS routing include). Reach for these when you want explicit Django parity over the curated djust new experience.

Spotted a typo or want to improve this page? Edit on GitHub →