Saturday 15 January 2011

python - Django REST framework - Serializing and Deserializing a list of primitive types -


Elephant's work is to use a serializer to serial a list of primitive types that say integer or String, and then deserialize this list again it should be really easy, but in some way I can not do quite a lot of it. I have been able to sort a simple model and it looks like this:

  {'title': u'something ',' description ': u'sldfj', 'price' : Decimal ('78 .56 '),' Numbers': [3, 2, 1]}   

... So what do I have to do to rebuild the list of numbers? My serializer looks like this:

  class OfferSerializer (serializers.Serializer): title = serializers.CharField () Description = serializers.CharField (required = false) value = serializers.DecimalField () number Val: setattr (example, key, wal) return example return proposal (for example: attrs.items), for example: Serializers.IntegerField (required = false) def restore_object (self, attrs, example = none): ** attrs) can call a bus  ListField (IntField ()) with monogyagin and everything is fine. Do I have to write my own listcriber?  

Thank you ...

If you just have a regular field < Using / code> requires a proper serialization.

If you also need deserialization, then writing the custom field type is probably the best option, the rest of the framework is not yet a generic list or Dutch container field.

No comments:

Post a Comment