Assign JSON field to model variable in django -


i having json like:

{    "name": "rahul",    "2or4": 2,  } 

here,

how can assign model variable : twoorfour jason field value "2or4" can not have variable start integer.

i new django. using django-rest-framework api.

if using djangorestframework need override to_representation function in serializer

http://www.django-rest-framework.org/api-guide/serializers/#overriding-serialization-and-deserialization-behavior

should this

def to_representation(self, obj)     serialized_data = super(serializerclassname, self).to_representation(obj)     serialized_data["2or4"] = serialized_data["twoorfour"]     //remove old field name     del serialized_data["twoorfour"]     return serialized_data 

this code should work serializerclassname class name of serializer


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -