drf-nested-routers
drf-nested-routers copied to clipboard
NestedSimplerRouter with nested>0 doesn't allow for no prefix in the url parameter
If I have a URL path such as:
/api/users/{username}
When I nest this with some child element, I get the the lookup
value given toNestedSimpleRouter
prepended:
routers.NestedSimpleRouter(router, api_path_users, lookup="username")
/api/users/{username_username}/books/
Is there a way to not have this prepend happen? I've tried working with parent_lookup_kwargs
and so on, but to no avail. Any ideas how to make it so the url would be /api/users/{username}/books/
?
Thanks!
If I have a URL path such as:
/api/users/{username}
When I nest this with some child element, I get the the
lookup
value given toNestedSimpleRouter
prepended:routers.NestedSimpleRouter(router, api_path_users, lookup="username")
/api/users/{username_username}/books/
Is there a way to not have this prepend happen? I've tried working with
parent_lookup_kwargs
and so on, but to no avail. Any ideas how to make it so the url would be/api/users/{username}/books/
?Thanks!
Hi,
I think there is no such possibility.
lookup parameter in the NestedSimpleRouter ensures that every URL kwarg will be unique. So if you have many lookups named 'slug' you will end up with 'username_slug' and 'book_slug'.
I guess it would be better to have a lookups named 'name' or 'slug' for username as 'username' is an instance and 'name' or 'slug' could be his lookups. Then 'username_name' or 'username_slug' would be much more readable.