{"action":"created","issue":{"url":"https://api.github.com/repos/chibisov/drf-extensions/issues/87","labels_url":"https://api.github.com/repos/chibisov/drf-extensions/issues/87/labels{/name}","comments_url":"https://api.github.com/repos/chibisov/drf-extensions/issues/87/comments","events_url":"https://api.github.com/repos/chibisov/drf-extensions/issues/87/events","html_url":"https://github.com/chibisov/drf-extensions/pull/87","id":81360524,"number":87,"title":"Respect parent lookup regex value (sending parent viewset to NestedRegistryItem)","user":{"login":"frwickst","id":3242350,"avatar_url":"https://avatars.githubusercontent.com/u/3242350?v=3","gravatar_id":"","url":"https://api.github.com/users/frwickst","html_url":"https://github.com/frwickst","followers_url":"https://api.github.com/users/frwickst/followers","following_url":"https://api.github.com/users/frwickst/following{/other_user}","gists_url":"https://api.github.com/users/frwickst/gists{/gist_id}","starred_url":"https://api.github.com/users/frwickst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frwickst/subscriptions","organizations_url":"https://api.github.com/users/frwickst/orgs","repos_url":"https://api.github.com/users/frwickst/repos","events_url":"https://api.github.com/users/frwickst/events{/privacy}","received_events_url":"https://api.github.com/users/frwickst/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-27T09:09:32Z","updated_at":"2015-06-02T07:04:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/chibisov/drf-extensions/pulls/87","html_url":"https://github.com/chibisov/drf-extensions/pull/87","diff_url":"https://github.com/chibisov/drf-extensions/pull/87.diff","patch_url":"https://github.com/chibisov/drf-extensions/pull/87.patch"},"body":"A try for this was made in #63 but it did not lead anywhere and this is really starting to become a problem for me so hopefully this is good enough :)\r\n\r\n### Problem\r\nSay that you have a user route (/users) and you do not want to expose the `id` value of the user, so you use the users email instead. Making a detailed route look like /users/frwickst@gmail.com. You test the route and notice that you get a 404 page. This is because the default lookup regex is `[^/.]+`, and this works fine for most routes, but not when there is a dot (.) in the route. And since dots are [valid in a url](http://stackoverflow.com/a/7555609) we this is a shame. The solution to this is to set your `lookup_filed` to 'email' and write your own [lookup_value_regex](http://www.django-rest-framework.org/api-guide/routers/#simplerouter) in your view. In this case we could set it to something fancy such as `[^@]+@[^@]+\\.[^@/]+`. And voilà, the route now works.\r\n\r\nThe problem is that this regex value is **not** respected in the nested routers that are included in drf-extensions, instead the hard coded value of [`[^/.]+`](https://github.com/chibisov/drf-extensions/blob/f3f62290bd9970da5c1fac02275b87cfbb5ab73b/rest_framework_extensions/routers.py#L178) is used.\r\n\r\n### Solution\r\nBy default we do not have access to the parents regex value as it is stored in the parents viewset, which we don't have access to either. This pull requests lets the viewset of the parent be passed to the ´NestedRegistryItem´ class, exposing all viewset functions and variables, including the regex. The regex is then used when creating the `get_parent_prefix()`, and falls back on the default value of `[^/.]+` if no regex is set.\r\n\r\n### Caveat\r\nThere is a second thing here to keep in mind. If using custom lookup_field values in the view, one also needs to set the `lookup_url_kwarg` value when using nested router, in the example above it would be `lookup_url_kwarg = 'parent_lookup_email'`. This has to do with the way the `NestedViewSetMixin` is built, and can probably be fixes as well (just not in this pull request)."},"comment":{"url":"https://api.github.com/repos/chibisov/drf-extensions/issues/comments/107833086","html_url":"https://github.com/chibisov/drf-extensions/pull/87#issuecomment-107833086","issue_url":"https://api.github.com/repos/chibisov/drf-extensions/issues/87","id":107833086,"user":{"login":"chibisov","id":522462,"avatar_url":"https://avatars.githubusercontent.com/u/522462?v=3","gravatar_id":"","url":"https://api.github.com/users/chibisov","html_url":"https://github.com/chibisov","followers_url":"https://api.github.com/users/chibisov/followers","following_url":"https://api.github.com/users/chibisov/following{/other_user}","gists_url":"https://api.github.com/users/chibisov/gists{/gist_id}","starred_url":"https://api.github.com/users/chibisov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chibisov/subscriptions","organizations_url":"https://api.github.com/users/chibisov/orgs","repos_url":"https://api.github.com/users/chibisov/repos","events_url":"https://api.github.com/users/chibisov/events{/privacy}","received_events_url":"https://api.github.com/users/chibisov/received_events","type":"User","site_admin":false},"created_at":"2015-06-02T07:04:46Z","updated_at":"2015-06-02T07:04:46Z","body":"I'll look at this pull request as soon as possible"}}