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']  # test@test.test
       balance = user_data['profile']['balance'] # 100.0
       roles = user_data['roles'] # [1, 2, 3]
       ...   

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.

Files for drf-nested-multipart-parser, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size drf_nested_multipart_parser-0.0.2-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size drf-nested-multipart-parser-0.0.2.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page