Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to specify url and view names in detail_route and list_route #1892

Closed
abraithwaite opened this issue Sep 20, 2014 · 4 comments
Closed

Comments

@abraithwaite
Copy link

I was wondering if there was any plan to add this to DRF?

I'd like to be able to do something like this:

class MyViewSet(ModelViewSet):
    queryset = Users.objects.all()

    @detail_route(methods=["get"], name='stats-aggregation', method_url='stats')
    def statistics_aggregation(self, request, pk=None):
        do_cool_things(request, pk)

And have that appear as a url in the form of /users/4/stats and have the name be stats-aggregation.

It looks like it would only be a matter of adding another argument to the decorator function, binding that to the function object, then adding it as a kwarg to the route constructor (rather, the replace_methodname function).

I'd be willing to take a look at it myself, but I wanted to create an issue first to see if there's any interest or if that area of code is going to change significantly soon.

@tomchristie
Copy link
Member

See also #2010

@maryokhin
Copy link
Contributor

In my humble opinion, since routers follow the principle of convention over configuration, having too many arguments on dynamic routes would give too broad of a public API. I think something like:

SimpleRouter(trailing_slash=False, dasherize_routes=True)

Would probably solve 90% of the use-cases, with the other 10% falling into the custom router category.

@tomchristie
Copy link
Member

Closing as per #2010.

Given that the only use case I've seen for this is to allow underscored styles instead of hyphenated styles, it'd be better to see someone implement this in hypenated-routers pacakage or similar. The notes in #2010 detail how you'd do that, and we have extensive notes on rolling a third party package... http://www.django-rest-framework.org/topics/third-party-resources/

@abraithwaite
Copy link
Author

Works for me!

Cheers 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants