Ninja API for Wagtail
Project description
from ninja import ModelSchema
wagtail-ninja
alpha version.
usage
in your wagtail project do something like this:
# api.py
from ninja import NinjaAPI
from wagtail_ninja.router import WagtailNinjaPagesRouter
pages_router = WagtailNinjaPagesRouter()
api = NinjaAPI()
api.add_router("/pages/", pages_router)
and then in your urls:
# urls.py
from some.path.api import api as ninja_api
urlpatterns = [
...
path("api/wagtail/v3/", ninja_api.urls),
...
]
et voila.
you should be able to:
- find the OpenAPI Ninja UI under e.g. http://localhost:8000/api/wagtail/v3/docs
- get the schema (for further processing) from http://localhost:8000/api/wagtail/v3/openapi.json
annotating api_fields
just like with the original wagtail api, you can put arbitrary functions in api_fields and they will be evaluated.
to annotate these, you will quickly run into circular dependency hell, i.e.:
# schema.py
class MyPageSchema(ModelSchema):
class Meta:
model = MyPage
class OtherPageSchema(ModelSchema):
class Meta:
model = OtherPage
# models.py
class MyPage(Page):
api_fields = ['something']
def related_otherpage(self) -> OtherPageSchema:
related = ...
return OtherPageSchema.from_orm(related)
The "best" solution right now is to solve it like so:
def related_otherpage(self):
from .schema import OtherPageSchema
related = ...
return OtherPageSchema.from_orm(related)
@staticmethod
def type_fn():
from .schema import OtherPageSchema
return OtherPageSchema
related_otherpage._wagtail_ninja_type_fn = type_fn
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_ninja-0.1.10.tar.gz.
File metadata
- Download URL: wagtail_ninja-0.1.10.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fef0f0437c83e533c6169f8b1e13461249a21bfccc97546ffdd6235dd2def77c
|
|
| MD5 |
455b5555c7c5a68f1276ac409859e665
|
|
| BLAKE2b-256 |
472e3e9b6e97f8635923440ef61941d9831ac099ed0fb13e15bcfea6390f0e21
|
File details
Details for the file wagtail_ninja-0.1.10-py3-none-any.whl.
File metadata
- Download URL: wagtail_ninja-0.1.10-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de66eeb6d80ef7688157241900695b54bb64183632b95a0e1ba5c40ad363dd76
|
|
| MD5 |
fc6fcf06417e0cd407916609118b7512
|
|
| BLAKE2b-256 |
569459f79c45017bc60866b1d1b9cfab73f4158e4fe1d09fe966cad118708080
|