Django CRUD Generator
Most Django tutorials stop at python manage.py startapp and leave you staring at an empty models.py. This generator removes that blank-page step: describe your model — the app name, the class name, and each field with its type — and it writes out a complete CRUD skeleton for you. You get the model with typed fields and a sane __str__, a ModelForm, five views (list, detail, create, update, delete), the URL patterns, four ready-to-paste templates and an optional admin registration. Choose class-based views for the compact Django idiom, or function-based views if you prefer plain functions you can read top to bottom. Every file is generated in your browser as plain text with copy buttons — nothing is uploaded, stored or executed on this site.
1. App & model
2. Fields
3. Generated code
How it works
Use it in three steps. First, set the app name and the model name — the app is the Python package Django creates (bookstore), and the model is the class that maps to one database table (Book). Second, add fields: each row is a column, with a type from CharField through ForeignKey, plus per-type options such as max_length, decimal precision, upload_to and the on_delete policy for relations. Third, pick your view style and read the output — every file updates live as you type, and the findings panel flags problems before they ever reach makemigrations.
The generator emits one file per tab so you can paste them straight into a fresh app. models.py defines the class with the fields you typed: CharField rows carry their max_length, DecimalField rows carry max_digits and decimal_places, ForeignKey rows carry the target model, the on_delete policy and an optional related_name, and optional numeric or date fields get null=True and blank=True while text fields get blank=True only — the convention Django's own docs recommend. forms.py is a ModelForm that mirrors the model; switch it to an explicit field list if you want to hide columns from the form.
views.py gives you the five standard operations. In class-based mode each one is a three-line generic view; in function-based mode each is a small, commented function with the same behaviour, including POST-only deletes. urls.py names every route (app_name plus _list, _detail, _create, _update and _delete) so templates can build links with {% url %} instead of hard-coded paths. The four templates extend your base.html and use context_object_name so the list page iterates over books rather than object_list. Finally, admin.py registers the model with a sensible list_display and search_fields when you tick the option. After pasting, run makemigrations, migrate and runserver — the setup tab lists the exact commands in order.
- models.py
- The table definition: your fields with types and options, a Meta ordering, and a __str__ built from your first text field (or the primary key if you have none).
- forms.py
- A ModelForm for the create and edit pages — all model fields, or an explicit list when you want to hide columns.
- views.py
- List, detail, create, update and delete — as compact class-based views or readable function-based views with POST-only mutations.
- urls.py
- Namespaced routes (app_name plus five route names) so links and redirects never hard-code paths.
- templates/<app>/<model>_list.html
- The index page: one row per object with detail, edit and delete links, plus a friendly empty-state message.
- templates/<app>/<model>_detail.html
- A read-only view of every field driven by the model's own _meta, so it stays correct when you add columns later.
- templates/<app>/<model>_form.html
- The shared create/edit form with a CSRF token; the heading switches between Add and Edit automatically.
- templates/<app>/<model>_confirm_delete.html
- A confirmation page so a stray GET — from a prefetcher or a bad bot — can never delete a row.
- admin.py
- Optional ModelAdmin with list_display and search_fields, registered with a single decorator.
- setup.txt
- The exact command sequence: startapp, INSTALLED_APPS, include(), makemigrations, migrate, runserver.
Worked example: a bookshop in five minutes
Say you are building a bookshop. Type bookstore as the app name and Book as the model, then add title (CharField, 200), author (CharField, 120), pages (IntegerField, optional) and published_on (DateField, optional). The generator immediately renders models.py with those four fields, forms.py with a BookForm, and class-based views for BookListView, BookDetailView, BookCreateView, BookUpdateView and BookDeleteView.
Copy each file into bookstore/, add 'bookstore' to INSTALLED_APPS, wire path('books/', include('bookstore.urls')) into your root urls.py, then create the table and run the server:
python manage.py makemigrations bookstore
python manage.py migrate
python manage.py runserver
Point the browser at /books/ and you have a working list page, an add form, per-book detail pages with edit and delete links, and a confirmation page before anything is removed — in about five minutes, with no syntax errors to chase. The Book quick-start button above reproduces this exact setup.
Common mistakes this generator avoids
Blank-page mistakes that waste hours, all avoided by the generated code:
- null=True on CharField. Django's docs say keep null=False on string fields and use blank=True for form validation; the generator applies that split automatically (nullable numeric, date and foreign-key fields get both).
- Forgetting include() in the root urls.py. The app can be installed and migrated yet unreachable if the project never wires in its URLconf — setup.txt reminds you of the line.
- Templates in the wrong folder. Django looks for them under templates/<app>/; pasting into templates/ directly means a TemplateDoesNotExist at request time, and the generated filenames already carry the app name.
- Running before migrating. runserver before makemigrations and migrate fails with a no-such-table error; the setup tab orders the commands so you do not have to remember them.
- Deleting on GET. A delete link hit by a prefetcher removes rows instantly; the generated delete view only acts on POST, behind a confirmation page.
- Colliding field names. Naming a field pk or id collides with the automatic primary key, and Python keywords are not legal attribute names — the findings panel rejects both as you type.
Related tools
- Systemd Service Generator — running in production? Wrap gunicorn in a unit file so the app survives reboots.
- Nginx Server Block Generator — put nginx in front of Django for TLS, gzip and static files.
- GitIgnore Generator — keep .pyc caches, virtualenvs and .env secrets out of version control from day one.
- SQL Insert Generator — seeding the fresh tables? Build bulk INSERT statements for your initial data.
Suggested
Luke Keam | techgeek.biz