Open pbdeuchler opened 9 years ago
The mistake is in this line:
garden_router = router.register(r'gardens', GardenViewSet, base_name='garden')
Here you get a route, not the router itself, returned by register()
.
Therefore, to avoid confusion, you should name it:
garden_routes = router.register(r'gardens', GardenViewSet, base_name='garden')
and then do router.urls
instead of garden_router.urls + plant_router.urls
. Hope that helps.
@pbdeuchler, please, close the issue if @maryokhin's comment helped.
Sorry for taking so long to get back to this... using this method apparently effects both regex groups when I set parent_query_lookups
with registering on plant_routes
, so I'm getting this error:
ImproperlyConfigured at /v1/
"^gardens/(?P<parent_lookup_gardens__plants>[^/.]+)/plants/(?P<parent_lookup_gardens__plants>[^/.]+)/notes/$" is not a valid regular expression: redefinition of group name 'parent_lookup_gardens__plants' as group 2; was group 1
new code:
# url router
router = ExtendedDefaultRouter()
garden_routes = router.register(r'gardens', GardenViewSet, base_name='garden')
garden_routes.register(r'notes', GardenNoteViewSet, 'gardens-note', parents_query_lookups=['gardens'])
plant_routes = garden_routes.register(r'plants', PlantViewSet, 'gardens-plant', parents_query_lookups=['gardens'])
plant_routes.register(r'notes', PlantNoteViewSet, 'gardens-plants-note', parents_query_lookups=['gardens__plants'])
plant_routes.register(r'metrics', PlantMetricViewSet, 'gardens-plants-metric', parents_query_lookups=['gardens__plants'])
@pbdeuchler you were able to fix the issue?
I have not @auvipy, but I also haven't worked on this project in a while
the issue is valid then?
I would believe so
Expected Routes:
Router:
With the error coming from: