Add django-ninja as REST API option#6088
Conversation
|
I pulled this for my newest project and its working well for me! |
|
does this pr planned to get merged |
Yes, at some point, was waiting for folks to try it out and share their experience. |
# Conflicts:
# {{cookiecutter.project_slug}}/pyproject.toml
# {{cookiecutter.project_slug}}/requirements/base.txt
# {{cookiecutter.project_slug}}/requirements/local.txt
There was a problem hiding this comment.
Pull request overview
Adds a new rest_api Cookiecutter option to support choosing between no REST API, Django REST Framework, or Django Ninja, and updates the generated project scaffold, tests, and CI matrix accordingly.
Changes:
- Replaces
use_drfwithrest_apiacross template config, dependencies, and documentation. - Introduces Django Ninja API scaffolding (router, schemas, URL wiring) alongside DRF.
- Expands CI and template-generation coverage for REST API + username-type combinations.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py |
Minor formatting tweak to method signature spacing. |
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_views.py |
Adds Ninja API view tests and gates DRF tests behind rest_api. |
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_urls.py |
Adds Ninja URL name/path assertions and gates DRF vs Ninja URL tests. |
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_openapi.py |
Switches OpenAPI/docs URL assertions based on selected REST API. |
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py |
Adds Ninja router endpoints alongside DRF ViewSet under rest_api. |
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/schema.py |
Adds Ninja ModelSchema definitions for user API responses/updates. |
{{cookiecutter.project_slug}}/requirements/local.txt |
Updates DRF-stubs conditional to use rest_api. |
{{cookiecutter.project_slug}}/requirements/base.txt |
Adds django-ninja dependencies under rest_api selection. |
{{cookiecutter.project_slug}}/pyproject.toml |
Updates mypy DRF plugin conditional to use rest_api. |
{{cookiecutter.project_slug}}/manage.py |
Adds a blank line after module docstring. |
{{cookiecutter.project_slug}}/config/urls.py |
Wires DRF vs Ninja API URLs based on rest_api. |
{{cookiecutter.project_slug}}/config/settings/production.py |
Updates DRF-only settings blocks to key off rest_api. |
{{cookiecutter.project_slug}}/config/settings/local.py |
Reformats EMAIL_BACKEND env call (line wrapping). |
{{cookiecutter.project_slug}}/config/settings/base.py |
Adds Ninja installed apps and enables CORS middleware for any REST API choice. |
{{cookiecutter.project_slug}}/config/api.py |
Introduces Ninja NinjaAPI instance and router registration for users. |
tests/test_cookiecutter_generation.py |
Adds new context cases for rest_api values and removes use_drf. |
hooks/post_gen_project.py |
Removes DRF/Ninja starter files depending on selected rest_api option. |
docs/1-getting-started/project-generation-options.rst |
Documents new rest_api option and adds Django Ninja link. |
cookiecutter.json |
Adds rest_api option and removes use_drf. |
README.md |
Updates example prompts to include rest_api selection. |
.github/workflows/ci.yml |
Updates CI matrix and adds jobs covering DRF/Ninja + username combinations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/schema.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_urls.py
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/schema.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_urls.py
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/api/test_urls.py
Show resolved
Hide resolved
|
Let's give this a try |
Description
use_drf=y/noption torest_api=None/DRF/Django NinjaChecklist:
Rationale
While DRF is a solid option, Django Ninja has gained popularity over the years and is the only other option listed in the ecosystem page.
Fix #4923
Disclaimer
I'm not super familiar with Django Ninja, so I might not have gone with the most idiomatic way to write view and schema. That might be an area of focus if you're more familiar with the framework.