python - Post Object or array of Objects to API -



python - Post Object or array of Objects to API -

i have rest api endpoint can post json object or json array of objects.

i managed redefining create method of modelviewset:

def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data, many=false) if serializer.is_valid(): serializer.save() headers = self.get_success_headers(serializer.data) homecoming response(serializer.data, status=status.http_201_created, headers=headers) else: serializer = self.get_serializer(data=request.data, many=true) if serializer.is_valid(): serializer.save() headers = self.get_success_headers(serializer.data) homecoming response(serializer.data, status=status.http_201_created, headers=headers) homecoming response(serializer.errors, status=status.http_400_bad_request)

i used is_valid() serializer know if info contains object or array (many set true or false), because of lose serializer validation other purposes field validations.

is there improve way accomplish behaviour?

should instead create function url able post array of objects? rest way back upwards both operations?

django rest framework not back upwards mass object creation default, there packages out there add together back upwards it, such django rest framework bulk.

it can made work routers slight modifications. should allow looking for.

because of lose serializer validation other purposes field validations.

this because not passing in serializer context, generic views automatically.

python arrays django rest django-rest-framework

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

SQL Server : need assitance parsing delimted data and returning a long concatenated string -