This version brings few enahcments
1) Serialisation context now has request and response code
Python
class SchemaWithCustomSerializer(Schema):
test1: str
test2: str
model_serializer(mode="wrap")
def ser_model(self, handler, info):
request = info.context["request"] !!!
response_status = info.context["response_status"] !!!
return handler(self)
2) With `PatchDict` you can quickly define schemas with all optional fields and use it as dict with ONLY fields that were passed in request payload (aka patch requests)
Python
from ninja import PatchDict
class SomeSchema(Schema):
name: str
description: str
due_date: date
Note all fields a required
api.patch("/patch")
def modify_data(request, payload: PatchDict[SomeSchema]):
payload ! <--- payload is a type of dict and contains only keys that were passed in request body (validated with SomeSchema)
for attr, value in payload.items():
setattr(obj, attr, value)
obj.save()
All changes
* Support import string in router.add_router by martinsvoboda in https://github.com/vitalik/django-ninja/pull/1256
* Add default headers for NinjaClientBase instance by c4ffein in https://github.com/vitalik/django-ninja/pull/1259
* Fix issue when consulting request attributes while using mocked request by acuriel in https://github.com/vitalik/django-ninja/pull/1244
* Allow generic filter types by eugenenelou in https://github.com/vitalik/django-ninja/pull/1212
* DRF-style data property for responses in tests by c4ffein in https://github.com/vitalik/django-ninja/pull/1260
* Pass serialisation context to model_dump (fixes 1233) by scorpp in https://github.com/vitalik/django-ninja/pull/1261
* PatchDict util by vitalik in https://github.com/vitalik/django-ninja/pull/1262
New Contributors
* martinsvoboda made their first contribution in https://github.com/vitalik/django-ninja/pull/1256
* acuriel made their first contribution in https://github.com/vitalik/django-ninja/pull/1244
* eugenenelou made their first contribution in https://github.com/vitalik/django-ninja/pull/1212
* scorpp made their first contribution in https://github.com/vitalik/django-ninja/pull/1261
**Full Changelog**: https://github.com/vitalik/django-ninja/compare/v1.2.2...v1.3.0