tomchristie/django-rest-framework — pull request #980 by matklad (2013-07-11 22:56:34+00:00)
Title: add endpoint argument to @action and @link decorators

Hello!

There is one problem with `@action` and `@link` decorators at the moment: you can not specify endpoint name, it must be the same as python method name. This is painful if you want to use hyphens instead of underscores in urls.

For example, now
```python
@action(permission_classes=[IsAdminOrIsSelf])
def set_password(self, request, pk=None):
...
```
gets routed to
`^users/{pk}/set_password/$`. As I understand, there is no obvious, simple and non-magical way to route it to `^users/{pk}/set-password/$`.

So here is what I propose in this pull request:

```python
@action(permission_classes=[IsAdminOrIsSelf], endpoint='set-password')
def set_password(self, request, pk=None):
...
```
and it's routed to, obviously, `^users/{pk}/set-password/$`.

The other way to solve hyphen-underscore problem would be just to substitute them not only in name but also in url.

However, I find approach with explicit names better because
* explicit is better than implicit
* it's more backwards-compatible
* it's more general

The drawbacks are that the code gets a bit more complicated and urls naming remains implicit.

So

```python
@action(endpoint='fancy-name')
def do_stuff(self, request, pk=None):
...
```
will have url-pattern `^users/{pk}/fancy-name/$` and name: `'user-do-stuff'`.

PS. djangorestframework is fantastic! =)