Skip to content

Project Lead - OpenCoCA : Adds a management command that generates views, forms, urls, admin, and templates based off the contents of models.py

License

Notifications You must be signed in to change notification settings

opencoca/STARTR-WEB-OPS-django-startr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Got it! Here's a fully revised version, free of baked goods and with a fun, startup-inspired tone:


Django Startr

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.


Installing

pip install django-startr

Add 'django_startr' to INSTALLED_APPS.


Usage

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

Views

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.


Niceties Included:

  • form_class is set to a ModelForm in your forms.py.
  • context_object_name is a clean, slugified version of your model name (e.g., rockets for DetailView, or rockets_list for ListView).
  • If your model has a unique slug field, it's automatically set as the slug_field and slug_url_kwarg.
  • get_success_url sends users to the object’s DetailView after updates or deletes.

Templates

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 and UpdateView display a form and link back to the list view.
  • The DeleteView has a confirmation button and links back to the list view.

Admin Setup

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.


Some Extras:

  • list_select_related: Automatically set for all foreign key fields, improving query performance.
  • list_display: Includes all model fields except the id and ManyToManyFields.
  • list_filter: Smart filtering for fields with choices, booleans, and foreign keys with fewer than 100 related objects.
  • search_fields: Automatically set for CharField and TextField.

The Future of Django Startr

Our top three goals are:

  1. Allow models to be regenerated when new ones are added.
  2. Automatically generate tests for each app and model.
  3. Add tests to Django Startr itself.

Pull requests are always welcome!


License

Copyright 2019–2023 12787326 Canada Inc.

Licensed under the AGPLv3: https://opensource.org/licenses/agpl-3.0

About

Project Lead - OpenCoCA : Adds a management command that generates views, forms, urls, admin, and templates based off the contents of models.py

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 76.2%
  • HTML 23.8%