-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add django-ninja as REST API option
#6088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
browniebroke
merged 25 commits into
cookiecutter:main
from
browniebroke:feat/django-ninja
Mar 1, 2026
Merged
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
98607c8
Add Django Ninja as an option
browniebroke dfa157f
Move additional CI jobs to run outside of Docker
browniebroke d01edb2
Port openapi tests for Django Ninja
browniebroke a6063ca
Add tests for Django Ninja views
browniebroke 8ef2739
Fix bug in post-gen hooks
browniebroke a8f9475
Add missing import in URL file
browniebroke db35b09
Fix code styles issues and remove all API files where no REST APIs
browniebroke 6a40d62
Fix casing of Django Ninja option
browniebroke 5f81d0e
Fix more linting issues
browniebroke 2cad029
Fix minor ruff styling issues
browniebroke d51cd33
Install django-cors-headers with Django-ninja
browniebroke 31a12ab
Tweak formatting issue
browniebroke 43c37c3
Adjust Django Ninja tests
browniebroke 73392d2
Fix Ninja list test to cover for username variations
browniebroke 6e658ea
Fix Ninja update view test
browniebroke a2dbce1
Default Ninja endpoints to authenticated
browniebroke 77e83b7
Fix Django ninja link in the docs
browniebroke 21d553b
Merge branch 'main' into feat/django-ninja
browniebroke 9d25570
Bump django-ninja to the latest version
browniebroke e8e7121
Update django-ninja views
browniebroke 4381fac
Update django-ninja URLs tests
browniebroke 1d924fc
Minor fixes
browniebroke 3036585
Add update_current_user view
browniebroke fd2fd08
Fix linting
browniebroke 95c78c0
Address comments from code review
browniebroke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from django.contrib.admin.views.decorators import staff_member_required | ||
| from ninja import NinjaAPI | ||
| from ninja.security import SessionAuth | ||
|
|
||
| api = NinjaAPI( | ||
| urls_namespace="api", | ||
| auth=SessionAuth(), | ||
| docs_decorator=staff_member_required, | ||
| ) | ||
|
|
||
| api.add_router("/users/", "{{ cookiecutter.project_slug }}.users.api.views.router") | ||
browniebroke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/schema.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from django.urls.base import reverse | ||
browniebroke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from ninja import ModelSchema | ||
|
|
||
| from {{ cookiecutter.project_slug }}.users.models import User | ||
|
|
||
|
|
||
| class UpdateUserSchema(ModelSchema): | ||
| class Meta: | ||
| model = User | ||
| {%- if cookiecutter.username_type == "email" %} | ||
| fields = ["name"] | ||
| {%- else %} | ||
| fields = ["username", "name"] | ||
browniebroke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {%- endif %} | ||
|
|
||
|
|
||
| class UserSchema(ModelSchema): | ||
| url: str | ||
|
|
||
| class Meta: | ||
| model = User | ||
| {%- if cookiecutter.username_type == "email" %} | ||
| fields = ["email", "name"] | ||
| {%- else %} | ||
| fields = ["username", "email", "name"] | ||
| {%- endif %} | ||
|
|
||
| @staticmethod | ||
| def resolve_url(obj: User): | ||
| {%- if cookiecutter.username_type == "email" %} | ||
| return reverse("api:retrieve_user", kwargs={"pk": obj.pk}) | ||
| {%- else %} | ||
| return reverse("api:retrieve_user", kwargs={"username": obj.username}) | ||
| {%- endif %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.