Skip to content

0.17.0

Compare
Choose a tag to compare
@vitalik vitalik released this 03 Feb 22:03
· 625 commits to master since this release

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:

New Contributors

Full Changelog: v0.16.2...v0.17.0