Giter VIP home page Giter VIP logo

Comments (10)

chibisov avatar chibisov commented on August 12, 2024

Hi @Matt3o12

As i understood, list_route and detail_route behaves exactly as drf-extensions collection level controllers:

...
from rest_framework_extensions.decorators import action
...

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

    @action(is_for_list=True)  # equals @list_route()
    def confirm_email(self, request, pk=None):
        return Response(['email confirmed'])

    @action()  # equals @detail_route()
    def set_password(self, request, pk=None):
        return Response(['password changed'])

from drf-extensions.

chibisov avatar chibisov commented on August 12, 2024

#31 created ticket for documentation

from drf-extensions.

Matt3o12 avatar Matt3o12 commented on August 12, 2024

Not quite.
list_route and detail_route let you decided one or more HTTP methods. That means you can allow PUT and POST requests to be handled within the same method.
For example:

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

    @action(is_for_list=True)  # equals @list_route(): pk will never be given.
    def confirm_email(self, request, pk=None):
        return Response(['email confirmed'])

    @action()  # equals @detail_route(): pk will always be given.
    def set_password(self, request, pk=None):
        return Response(['password changed'])

       @detail_route(methods=["DELETE"])
            def delete_something():
            return Response("Something deleted")

       @detail_route(methods=["POST", "PUT"])
            def update_something():
            return Response("Something has been updated.”)

Furthermore, the @list_route/detail_rout decorator’s syntax is much more clearer and @action and @link has been marked for pending deprecation.
What they don’t support is an endpoint (e.g. “set-password” instead of “set_password”).

On Sep 5, 2014, at 8:23 AM, Gennady Chibisov [email protected] wrote:

Hi @Matt3o12 https://github.com/Matt3o12
As i understood, list_route and detail_route behaves exactly as drf-extensions collection level controllers http://chibisov.github.io/drf-extensions/docs/#collection-level-controllers:

...
from rest_framework_extensions.decorators import action
...

class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer

@action(is_for_list=True)  # equals @list_route()
def confirm_email(self, request, pk=None):
    return Response(['email confirmed'])

@action()  # equals @detail_route()
def set_password(self, request, pk=None):
    return Response(['password changed'])


Reply to this email directly or view it on GitHub #30 (comment).

from drf-extensions.

chibisov avatar chibisov commented on August 12, 2024

list_route and detail_route let you decided one or more HTTP methods

It's always was possible with @action decorator https://github.com/chibisov/drf-extensions/blob/master/rest_framework_extensions/decorators.py#L17

from drf-extensions.

Matt3o12 avatar Matt3o12 commented on August 12, 2024

Thanks, I didn’t know that.
Still, I think the syntax is much more clearer and the action decorator will soon be deprecated.

On Sep 5, 2014, at 3:20 PM, Gennady Chibisov [email protected] wrote:

list_route and detail_route let you decided one or more HTTP methods

It's always was possible with @action decorator https://github.com/chibisov/drf-extensions/blob/master/rest_framework_extensions/decorators.py#L17 https://github.com/chibisov/drf-extensions/blob/master/rest_framework_extensions/decorators.py#L17

Reply to this email directly or view it on GitHub #30 (comment).

from drf-extensions.

chibisov avatar chibisov commented on August 12, 2024

Feel free to make a pull request ;)

from drf-extensions.

ybendana avatar ybendana commented on August 12, 2024

I'm seeing this issue also with the ExtendedDefaultRouter using DRF 2.4.4.

from drf-extensions.

acastellana avatar acastellana commented on August 12, 2024

In DRF 2.4.4 neither @link(is_for_list=True) nor @action(is_for_list=True) work properly. Any advance on this issue?

Thanks!

Update. Seems that DRF 2.4.4 already has a @list_route() decorator

Update. Moved to another issue #54

from drf-extensions.

chibisov avatar chibisov commented on August 12, 2024

Please, don't use collection level controllers and controller endpoint name with DRF => 2.4. These features are hard to maintain because of new extra link and actions

If you want to use nesting facilities you should mixin NestedRouterMixin into your router.

Be careful. ExtendedDefaultRouter and ExtendedSimpleRouter includes deprecated features and can't be used with DRF > 2.4

If you steel have problems, reopen this issue.

from drf-extensions.

magarcia avatar magarcia commented on August 12, 2024

This issue still existing as I say in #91.

from drf-extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.