This release brings few long awaited features:
Smarter schema
Now you can access orm instance attributes inside schema with resolvers:
class TaskSchema(Schema):
title: str
is_completed: bool
owner: Optional[str]
lower_title: str
@staticmethod
def resolve_owner(obj): # <------- !!!!!!
if not obj.owner:
return
return f"{obj.owner.first_name} {obj.owner.last_name}"
def resolve_lower_title(self, obj): # <-------- !!!!!!
return self.title.lower()
Field aliases now support django template variables dotted syntax:
class TaskSchema(Schema):
...
last_comment: str = Field(..., alias="comment_set.0.text")
Thanks to @SmileyChris
Pagination output
Now default paginated output returns a dict with items
and count
You can now override both input and output schemas for custom pagination:
class CustomPagination(PaginationBase):
class Input(Schema):
page: int
class Output(Schema):
items: List[Any]
total_pages: int
current_page: int
def paginate_queryset(self, queryset, pagination: Input, **params):
return {
'items': ...,
'total_pages': ...,
'current_page': ...,
}
All updates:
- Improved pagination by @vitalik
- Smarter schema that handles dotted aliases and resolver methods by @SmileyChris #317
- Add support for union type in payload by @AkeemMcLennon #301
- Export OpenAPI schema management cmd by @stefanitsky #288
- First key derivation optimization by @mom1 #344
**kwargs
not required anymore for pagination by @mom1 #285
New Contributors
Full Changelog: v0.16.2...v0.17.0