Django REST framework - redux-form connector
Project description
drfrf
Django REST framework - redux-form connector
Installation
$ pipenv install drfrf
Usage
Import and use one of ValidateCreateMixin
or ValidateUpdateMixin
:
from drfrf import ValidateCreateMixin, ValidateUpdateMixin
from rest_framework import viewsets
from rest_framework.decorators import detail_route, list_route
from shop.models import CartItem
from shop.serializers import CartItemSerializer
class CartItemViewSet(ValidateCreateMixin, ValidateUpdateMixin, viewsets.ModelViewSet):
queryset = CartItem.objects.all()
serializer_class = CartItemSerializer
@list_route(methods=["post"], url_path="validate")
def validate_list(self, request):
return self.validate_create(request)
@detail_route(methods=["post"], url_path="validate")
def validate_detail(self, request, **kwargs):
return self.validate_update(request, **kwargs)
Posting invalidate data to /items/validate
would return error messages:
HTTP/1.1 400 Bad Request
Content-Length: 99
Content-Type: application/json
{
"amount": [
"Your current credit is 36€, please top-up your account before adding to your cart."
]
}
Browse the complete example here: https://github.com/Theodo-UK/drfrf/tree/master/example/backend/shop
API
ValidateCreateMixin
Exposes one method: validate_create
takes Request, validates the input data against the provided serializer and returns a Response.
ValidateUpdateMixin
Exposes one method: validate_update
takes Request with kwargs, validates the input data against the provided serializer and returns a Response.
Frontend integration
If you're using redux-form in your frontend, check out drfrf for the front.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.