From 33f1cd24cd84cc7e0ec2a76d1d8fed04dd401435 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 20 Feb 2014 14:55:10 +0000 Subject: Latest docs build --- api-guide/fields.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'api-guide/fields.html') diff --git a/api-guide/fields.html b/api-guide/fields.html index 2a8dd3cb..2a0ac6ef 100644 --- a/api-guide/fields.html +++ b/api-guide/fields.html @@ -270,6 +270,7 @@ class AccountSerializer(serializers.HyperlinkedModelSerializer): expired = serializers.Field(source='has_expired') class Meta: + model = Account fields = ('url', 'owner', 'name', 'expired')

Would produce output similar to:

@@ -285,7 +286,7 @@ class AccountSerializer(serializers.HyperlinkedModelSerializer):

WritableField

A field that supports both read and write operations. By itself WritableField does not perform any translation of input values into a given type. You won't typically use this field directly, but you may want to override it and implement the .to_native(self, value) and .from_native(self, value) methods.

ModelField

-

A generic field that can be tied to any arbitrary model field. The ModelField class delegates the task of serialization/deserialization to it's associated model field. This field can be used to create serializer fields for custom model fields, without having to create a new custom serializer field.

+

A generic field that can be tied to any arbitrary model field. The ModelField class delegates the task of serialization/deserialization to its associated model field. This field can be used to create serializer fields for custom model fields, without having to create a new custom serializer field.

The ModelField class is generally intended for internal use, but can be used by your API if needed. In order to properly instantiate a ModelField, it must be passed a field that is attached to an instantiated model. For example: ModelField(model_field=MyModel()._meta.get_field('custom_field'))

Signature: ModelField(model_field=<Django ModelField instance>)

SerializerMethodField

@@ -400,7 +401,7 @@ Django's regular Custom fields

If you want to create a custom field, you'll probably want to override either one or both of the .to_native() and .from_native() methods. These two methods are used to convert between the initial datatype, and a primitive, serializable datatype. Primitive datatypes may be any of a number, string, date/time/datetime or None. They may also be any list or dictionary like object that only contains other primitive objects.

-

The .to_native() method is called to convert the initial datatype into a primitive, serializable datatype. The from_native() method is called to restore a primitive datatype into it's initial representation.

+

The .to_native() method is called to convert the initial datatype into a primitive, serializable datatype. The from_native() method is called to restore a primitive datatype into its initial representation.

Examples

Let's look at an example of serializing a class that represents an RGB color value:

class Color(object):
-- 
cgit v1.2.3