Features overview
1. ty official support
We now officially support ty type-checker!
2. Router.to_urlpatterns method was added
Now you including routers into the final urlpatterns is easier:
# urls.py
from django.urls import include
from dmr.routing import Router, path
from myapp.views import UserController
router = Router(
'api/',
[
path('user/', UserController.as_view(), name='users'),
],
)
urlpatterns = [
router.to_urlpatterns(namespace='api'),
]Docs: https://django-modern-rest.readthedocs.io/en/latest/pages/routing.html
3. @validate now supports reusable controllers
You can now use @validate with abstract controllers and type variables.
Just like @modify could before this release.
from abc import abstractmethod
from http import HTTPStatus
from typing import Generic, TypeVar
from django.http import HttpResponse
from dmr import Body, Controller, ResponseSpec, validate
from dmr.serializer import BaseSerializer
from dmr.types import safe_typevar
_SerializerT = TypeVar('_SerializerT', bound=BaseSerializer)
_RequestModelT = TypeVar('_RequestModelT')
_ResponseBodyT = TypeVar('_ResponseBodyT')
class ReusableController(
Controller[_SerializerT],
Generic[_SerializerT, _RequestModelT, _ResponseBodyT],
):
@validate(
ResponseSpec(
safe_typevar('_ResponseBodyT'),
status_code=HTTPStatus.CREATED,
),
)
def post(self, parsed_body: Body[_RequestModelT]) -> HttpResponse:
return self.to_response(self.convert(parsed_body))
@abstractmethod
def convert(self, parsed_body: _RequestModelT) -> _ResponseBodyT:
raise NotImplementedErrorNow, you can choose which decorator to use, they offer the same semantics for this feature.
See further docs: https://django-modern-rest.readthedocs.io/en/latest/pages/reusable-code.html#real-endpoints-support
Migration prompt
It covers all the breaking changes.
You are migrating a Python project from `django-modern-rest` 0.12.0 to 0.13.0.
Load the latest documentation from https://django-modern-rest.readthedocs.io/llms-full.txt
before making any changes.
Apply **all** of the following breaking changes to the codebase.
For each change, search the entire project (including tests, fixtures, and
any helper modules) before editing.
---
### 1. `dmr.routing.ExternalURL` → `dmr.routing.external_path`
`ExternalURL` was made protected, it should not be ever used directly by users.
Users must switch to `external_path` function API. Change the `ExternalURL` + `path()`
to use `external_path` API with the same arguments.What's Changed
Breaking changes
- Refactored public
routing.ExternalURLinto protected_ExternalURL,
useexternal_path()function instead, #1262
Features
- Added initial
tysupport, #1257 - Added support of reusable controllers with
@validate, #1259 - Added default value to
prefixparameter inRouter.__init__, #1267 - Added
to_urlpatternsfunction to includeRouter
instances intourlpatternsor other routers, #1262
Bugfixes
OpenAPIConfig.openapi_versionnow support anystrargument, #1252
Misc
- Improve reusable controllers docs, #1259
New Contributors
- @gokul-debugger made their first contribution in #1249
- @Girdharilal-aiml made their first contribution in #1264
- @kittywaresz made their first contribution in #1265
Full Changelog: 0.13.0...0.14.0