I'm using drf-nested-routers to create several nested API endpoints.
Let's take a look at the next piece of code in my routes.py file:
from rest_framework_nested.routers import SimpleRouter, NestedSimpleRoute
base_router = SimpleRouter()
base_router.register("categories", CategoryModelView)
dishes_types_router = NestedSimpleRouter(base_router, r"categories", lookup="category")
dishes_types_router.register(r"types_of_dishes", DishesTypeModelView, basename="dishes_type")
My question is: what does lookup="category"
in the fourth row do?
While going trough the source code of
drf-nested-routers
repository, I've found this explanation in the doc strings in bothNestedSimpleRouter
andNestedDefaultRouter
:The source code and the example that's talked about in the explanation.