Closed jrivera294 closed 9 years ago
Forget it. I solved it modifying the filter_queryset_by_parents_lookup method.
def filter_queryset_by_parents_lookups(self, queryset):
parents_query_dict = List.objects.get(name=self.get_parents_query_dict()['mail_list']).id
if parents_query_dict:
try:
return queryset.filter(id=parents_query_dict)
except ValueError:
raise NotFound
else:
return queryset
I believe you've made a bad hack. Just try to change parents_query_lookups=['mail_list']
to parents_query_lookups=['mail_list__name']
list_router = router.register(
r'lists',
ListViewSet,
base_name='list')
member_router = list_router.register(
r'members',
MemberViewSet,
base_name='member',
parents_query_lookups=['mail_list__name']) # <= Here
Well... it's embarrassing, When I was testing I typed mail_listname with one ''. And I hought that it will not work.
Thank you very much.
Hi, I'm having a problem with the drf-ext nested routes. I can change the lookup_field in a viewset without problems, but when I make a nested route with this view as parent, I get this error:
ValueError at /lists/asdf/members/ invalid literal for int() with base 10: 'asdf'
I think that its because the parent_query_lookup is pointing to the primary key of the list model, that is a number, not to the "name" field, that is a string. I can access /list/{name} without problems, but I cant make a nested route to this.
Urls:
Viewsets:
Models: