Skip to main content

Parser for nested params in multipart file upload

Project description

drf-nested-multipart-parser

DRF Parser for nested params in multipart file upload.

Usage

from drf_nested_multipart_parser import NestedMultipartParser
from rest_framework import viewsets

class YourViewSet(viewsets.ViewSet):
	parser_classes = (NestedMultipartParser,)

To enable JSON and multipart

from drf_nested_multipart_parser import NestedMultipartParser
from rest_framework.parsers import JSONParser
from rest_framework import viewsets

class YourViewSet(viewsets.ViewSet):
	parser_classes = (JSONParser, NestedMultipartParser)

Example:

Input data

user[email] = 'test@test.test'
user[name] = 'John Doe'

user[profile][balance] = 100.00
user[profile][phone_number] = '+996325698201'
user[profile][avatar] = avatar_file

user[roles][] = 1 
user[roles][] = 2 
user[roles][] = 3 
...

View

from drf_nested_multipart_parser import NestedMultipartParser
from rest_framework import viewsets

class YourViewSet(viewsets.ViewSet):
	parser_classes = (NestedMultipartParser,)

    def post(self, request):
       user_data = request.data.get('user')

       email = user_data['email']  
       balance = user_data['profile']['balance']
       roles = user_data['roles']
       ...   

Installation

pip install drf-nested-multipart-parser

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf-nested-multipart-parser-0.0.1.tar.gz (2.2 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page