Skip to main content

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:

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


Download files

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

Source Distribution

wagtail_ninja-0.1.10.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_ninja-0.1.10-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

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

Hashes for wagtail_ninja-0.1.10.tar.gz
Algorithm Hash digest
SHA256 fef0f0437c83e533c6169f8b1e13461249a21bfccc97546ffdd6235dd2def77c
MD5 455b5555c7c5a68f1276ac409859e665
BLAKE2b-256 472e3e9b6e97f8635923440ef61941d9831ac099ed0fb13e15bcfea6390f0e21

See more details on using hashes here.

File details

Details for the file wagtail_ninja-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_ninja-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 de66eeb6d80ef7688157241900695b54bb64183632b95a0e1ba5c40ad363dd76
MD5 fc6fcf06417e0cd407916609118b7512
BLAKE2b-256 569459f79c45017bc60866b1d1b9cfab73f4158e4fe1d09fe966cad118708080

See more details on using hashes here.

Supported by

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