python - django can't serialize non-model on post -


new django , trying send list of id's server update information. not want them model class, theres no need it. trying put them serializer make sure "clean". here code:

view class:

class update_cards(apiview):     # seems necessary or throw error     queryset = card.objects.all()     def post(self, request, board_id, format=none):         print request.data         serializer = cardmoveserializer(data=request.data, many=true)         #this throws error         print serializer.data          return response(serializer.data) 

serializer:

class cardmoveserializer(serializers.serializer):     card_id = serializers.integerfield()     lane_id = serializers.integerfield() 

error get:

[{u'lane_id': 21, u'card_id': 3}] #this show data coming across wire internal server error: /api/board/2/updatecards traceback (most recent call last):   file "/library/python/2.7/site-packages/django/core/handlers/base.py", line 115, in get_response     response = callback(request, *callback_args, **callback_kwargs)   file "/library/python/2.7/site-packages/django/views/generic/base.py", line 68, in view     return self.dispatch(request, *args, **kwargs)   file "/library/python/2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view     return view_func(*args, **kwargs)   file "/library/python/2.7/site-packages/rest_framework/views.py", line 327, in dispatch     response = self.handle_exception(exc)   file "/library/python/2.7/site-packages/rest_framework/views.py", line 324, in dispatch     response = handler(request, *args, **kwargs)   file "/users/crob/documents/workspace/tlckanban/python/rest/views.py", line 37, in post     print card_moves.data   file "/library/python/2.7/site-packages/rest_framework/serializers.py", line 499, in data     self._data = [self.to_native(item) item in obj] typeerror: 'nonetype' object not iterable 

what have done implemented simplejson parser now, feel not best way it:

def update_cards(request, board_id):     json_data = simplejson.loads(request.body)      moveindex in range(0, len(json_data)):         #do work       return jsonresponse(json_data, status=status.http_200_ok) 

thanks in advance!

you need accessing 'serializer.is_valid()' before accessing data. looks there's missing bit of api there - serializer.data should raise expection if accessed before validation.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -