Comments (10)
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.
#31 created ticket for documentation
from drf-extensions.
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.
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.
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.
Feel free to make a pull request ;)
from drf-extensions.
I'm seeing this issue also with the ExtendedDefaultRouter using DRF 2.4.4.
from drf-extensions.
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.
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.
This issue still existing as I say in #91.
from drf-extensions.
Related Issues (20)
- DRF-extensions queryset use select_related,show different sql result
- UniqueFieldsMixin should not validate field when `required=False` HOT 1
- Bulk create
- Django Cron Abandoned HOT 4
- Not compatible with django 3.2 HOT 1
- NestedViewSetMixin not working in custom actions
- My Cron Job runs twice
- Release compatible with Django 3.2 HOT 3
- "'Response' object has no attribute '_headers'" HOT 4
- Release the package with Django 3.2 support HOT 1
- get children is too slow! cache seem not very high perform
- distutils has been deprecated in Python 3.10 in favour of setuptools HOT 1
- We are getting AttributeError: 'Response' object has no attribute '_headers' HOT 2
- Nested router lookup by multiple fields HOT 1
- 500 error returns in case of invalid parent lookup HOT 3
- cache_response get error: inner() missing 1 required positional argument: 'request'
- Is this project still supported? HOT 5
- Can't get the nested routing to work after reading the docs.
- Will this library still be maintained and have new versions released? HOT 7
- Tests suite is failing with DRF 3.15.0 and beyond
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-extensions.