Skip to main content

Django utilities for codegen and DX improvement

Project description

Django hogwarts 🧙‍♂️

Management commands to generate views, urls and templates

Use CLI commands to generate:

  • basic create, update, list, detail views
  • urlpatterns from views with REST like path urls
  • form, table, detail templates (Bootstrap and django-crispy-forms by default)

all commands will respect (will not change) existing code


Installation

# pip
pip install django-hogwarts

# poetry
poetry add django-hogwarts

add hogwarts to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "hogwarts"
]

Usage

Check this to know what urls will be generated

Generate urls.py

Generates paths for views from views.py

python manage.py genurls <your-app-name>

Arguments:

  • --force-app-name, fan override app_name variable in urls.py
  • --override, -o fully overrides existing code in urls.py (previous code will be deleted)
  • --single-import, -s instead of importing individual view, imports just modulefrom . import views

Generate views.py

Generates create, update, detail, list views for model. Checkout the demo

python manage.py genviews <your-app-name> <model-name>

Arguments

  • --smart-mode, -s adds login required, sets user for CreateView and checks if client is owner of object in UpdateView
  • --model-is-namespace, -mn adds success_url with name model as namespace
  • --file, -f specify view file (example: "views/posts_view.py" or "new_views.py") in your app

Generate tests.py

It generates tests from urls.py for CRUD generic views only

python manage.py gentests <your-app-name>

Generate templates

Generates templates from template_names from views from given app

django-crispy-forms and crispy-bootstrap5 packages are required

python manage.py gentemplates <your-app-name>

Want to create own scaffolding templates?

  1. create folder, copy and customize from this templates
  2. add that folder to setting HOGWARTS_SCAFFOLD_FOLDER = "<your-folder>"

Scaffolding

Generates views, urls and templates for given app (every model in app)

python manage.py scaffold <your-app-name>

Roadmap

  • tests generator
  • maybe rest-framework support (let me know in issues)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_hogwarts-0.9.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

django_hogwarts-0.9.0-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file django_hogwarts-0.9.0.tar.gz.

File metadata

  • Download URL: django_hogwarts-0.9.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.3 Windows/10

File hashes

Hashes for django_hogwarts-0.9.0.tar.gz
Algorithm Hash digest
SHA256 d8875a4b1131a98eaefc36d4c7997f7f5c0fa070b8b1e46070d072973c4d2bed
MD5 6f70ce5e72bf25f5b19a54b6f692abdc
BLAKE2b-256 7c38938d8e1d15d03e6498d030f9003700a40f5d7e5ae3d86fc4e78c787200c2

See more details on using hashes here.

File details

Details for the file django_hogwarts-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: django_hogwarts-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.3 Windows/10

File hashes

Hashes for django_hogwarts-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94167e00b625bfa3c4022e0010167819837b5a3c34f5452468e3d0089de70c1e
MD5 3d62651b280da60575a23a7b3aba74d3
BLAKE2b-256 00cd61f468d815b10e1deecfc63ba16a5f6e9144cd981f24300fa0adb12ef8d5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page