A decorator that allows view actions to be nested and seeks to be integrated into DRF after proper tests are written.
I didn't try to create a lot of new stuff, i just edited the SimpleRouter and added a decorator
**Use at own risk.** No tests yet! 'Works for me' though.. :)
I've created this functionality because i was in need, and will try to add tests and better organisation to it when i have time.
Want to use it? Star so i know there's someone else besides me that will benefit from my efforts.
## Usage
my_app/views.py
from drf_nested_decorator.decorator import nested_detail_route
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from my_users.permission_classes import ActuallyOwnsCard, IsAwesome
from my_users.serializers import CardSerializer
from my_users.models import Card
class MyUserViewSet(mixins.RetrieveModelMixin, mixins.ListModelMixin, GenericViewSet):
authentication_classes = (SessionAuthentication, )
permission_classes = (IsAuthenticated, )
queryset = MyUser.objects.all()
serializer_class = MyUserSerializer
@nested_detail_route(['DELETE'], url_path='cards', permission_classes=(IsAwesome, ActuallyOwnsCard) + permission_classes)
def nested_cards(self, request, pk=None, nested_pk=None)
serializer = CardSerializer(Card.objects.get(pk=nested_pk))
return Response(serializer.data)
urls.py
from drf_nested_decorator.routers import NestedDecoratorSimpleRouter
from my_app.views import MyUserViewSet
router = NestedDecoratorSimpleRouter()
router.register(r'myuser', MyUserViewSet, base_name="myuser")
## To do:
- Add tests, for everything (no decorator tests in DRF found, find or create)
- Test with other packages like drf-nested-routers and drf-extensions
- No formal parameter nested_lookup on decorated method supplied ->> good error message
- Find out from what lower version this is supported, I'm using 3.1.3.
- Automatic lookup of nested model through a nested_queryset?
Metadata
Release files for drf-nested-decorator 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_nested_decorator-0.5-py3-none-any.whl | Python 3 | none | any | Details for drf_nested_decorator-0.5-py3-none-any.whl |
Release files / drf_nested_decorator-0.5-py3-none-any.whl
| Download URL | drf_nested_decorator-0.5-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3bb5483fec728f051c69343322b84a69b447ddabc7a40f572e10bb2ce49bfd3d
|
|
BLAKE2b-256 checksum How to use checksums |
539bf8382afd9bbf7e5c092b3d3fec0dc32220ae32329f6c90937285c2dbcdd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for drf-nested-decorator 0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.