Skip to content

Ability to have the default parameter name in urls. #180

Description

@trevorphillipscoding

Just want to start off by saying, what a great library. I love it!

I was wondering if there is a way currently, or maybe implement here in the future, have the default parameter catchers in the URL. For example...

Here are some URLs that I generated using the django-extensions library.

/api/v1/users/ 
/api/v1/users/<pk>/
/api/v1/users/<pk>/deductions/
/api/v1/users/<user_pk>/businesses/
/api/v1/users/<user_pk>/businesses/<pk>/
/api/v1/users/<user_pk>/reports/
/api/v1/users/<user_pk>/reports/<pk>/
/api/v1/users/<user_pk>/vehicles/
/api/v1/users/<user_pk>/vehicles/<pk>/

and here is what my urls.py file looks like with the nested routing.

router = routers.SimpleRouter()
router.register("", UserViewSet)

user_router = routers.NestedSimpleRouter(router, "", lookup="user")
user_router.register("businesses", BusinessViewSet)
user_router.register("reports", ReportViewSet)
user_router.register("vehicles", VehicleViewSet)

urlpatterns = [
    path("/", include(router.urls)),
    path("", include(user_router.urls)),
]

Obviously I could change the lookup key to something else but I want it to be the same as the 'default' way that I think DRF/Django uses?

I also use the library drf_yasg to generate a schema API page and my URLs look like so.
Screen Shot 2020-07-02 at 9 54 28 PM

Anyone have an idea how I could accomplish this?

Edit:
I want to elaborate more since I don't think I explained super well. I want to be able to put the default pk in the URL which then would make it {id} in the API webpage that I generated with drf_yasg

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions