Got it! Here's a fully revised version, free of baked goods and with a fun, startup-inspired tone:
Django Startr is here to turbocharge your project setup! With just a few commands, it auto-generates everything you need—views, forms, URLs, admin, and templates—for all the models in your models.py
. Say goodbye to tedious boilerplate and hello to more time for innovation.
Just add one URL pattern to your project's URLconf, and you're off! You’ll have list, detail, create, update, and delete views for every model in your app, ready to go.
If you want more control, you can choose which models to start from and skip the rest. Everything’s plug-and-play, and totally customizable.
pip install django-startr
Add 'django_startr'
to INSTALLED_APPS
.
Imagine your project is called TechRocket, and it has two apps: launch
and mission
.
python manage.py startr launch mission
This command generates the necessary files for all the models in both apps. If you only want specific models, like Rocket
and MissionControl
, you can narrow it down:
python manage.py startr launch mission:Rocket,MissionControl
To connect everything, add one URL pattern to your project's URLconf:
(r'^mission/', include('mission.urls')),
And voilà, you’ll have a working URL structure like this:
www.techrocket.com/mission/rocket
www.techrocket.com/mission/missioncontrol
If you want shorter URLs:
(r'^rocket/', include('mission.urls.rocket_urls')),
(r'^missioncontrol/', include('mission.urls.missioncontrol_urls')),
Now you’ve got:
www.techrocket.com/rocket
www.techrocket.com/missioncontrol
We keep things tidy by creating a views
directory, where each model gets its own views file (e.g., rocket_views.py
). There’s also an __init__.py
file that imports all the views, making it easy to call what you need.
Almost every method you can override in Django’s CBVs (class-based views) is stubbed out for you, so you can quickly jump in and customize as needed. The attributes and methods are laid out in the order they’re called for convenience.
- form_class is set to a
ModelForm
in yourforms.py
. - context_object_name is a clean, slugified version of your model name (e.g.,
rockets
forDetailView
, orrockets_list
forListView
). - If your model has a unique slug field, it's automatically set as the
slug_field
andslug_url_kwarg
. - get_success_url sends users to the object’s
DetailView
after updates or deletes.
The generated templates are kept minimalist, so you can easily modify them to fit your style. Each extends a model-specific base file (e.g., rocket_base.html
), which extends your project’s base.html
.
- The
ListView
template includes links to view, update, and delete items, plus an option to create new ones. - The
DetailView
shows the object and links to update or delete it. - The
CreateView
andUpdateView
display a form and link back to the list view. - The
DeleteView
has a confirmation button and links back to the list view.
For each model, Django Startr generates a ModelAdmin
using a custom mixin that makes setting up your admin interface super simple. By default, Django Startr guesses intelligent options for list_display
, list_filter
, and search_fields
to give you a full-featured admin panel without the hassle.
- list_select_related: Automatically set for all foreign key fields, improving query performance.
- list_display: Includes all model fields except the
id
andManyToManyFields
. - list_filter: Smart filtering for fields with
choices
, booleans, and foreign keys with fewer than 100 related objects. - search_fields: Automatically set for
CharField
andTextField
.
Our top three goals are:
- Allow models to be regenerated when new ones are added.
- Automatically generate tests for each app and model.
- Add tests to Django Startr itself.
Pull requests are always welcome!
Copyright 2019–2023 12787326 Canada Inc.
Licensed under the AGPLv3: https://opensource.org/licenses/agpl-3.0