drf-nested-routers
drf-nested-routers copied to clipboard
Router registry is not working as expected
Hey, thanks for this nice package! In our code we use this pattern:
from some_package.urls import some_other_router
main_router = DefaultRouter()
main_router.registry.extend(some_other_router.registry)
urlpatterns = [
re_path(r"api/v1/", include(router.urls)),
]
The problem while using this package is that nested_router.registry does not contain the parent resource in the name, so the API will end up being /api/v1/nameservers
instead of
/api/v1/domain/<domain_pk>/nameservers
My hack-ish solution is this one:
NESTED_ROUTERS = [
some_other_nested_router
]
for nested_router in NESTED_ROUTERS:
router._urls = router.urls + nested_router.urls
But I would very much prefer if I could avoid this.
Thanks!
Hi, @mcosti. Thanks for reporting it as an issue.
Yeah. I agree with you that would be better to not need to add the .urls together. That would also fix the root listing of resources.
Yet I could not figure out a clean way to do it after poking around DRF sourcecode for a while. If you get a solution for this, that would be very welcome :+1:
Hey @alanjds . Could you maybe share what you tried and it didn't work?
Thanks
This is a desirable improvement, would love to contribute if I can. Have either of you made headway on this?
I personally haven't, I just used the hack above in my project