From 9dbb49ef2265449427ec5e7745bf482bcf929e7f Mon Sep 17 00:00:00 2001 From: Mikkel Munch Mortensen <3xm@detfalskested.dk> Date: Fri, 20 Apr 2018 15:35:09 +0200 Subject: [PATCH] Docs: Match original argument names (#5889) Change argument names in overridden field methods to match those of the base classes. --- docs/api-guide/fields.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 6c68a5b81..5cb096f1c 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -588,8 +588,8 @@ Let's look at an example of serializing a class that represents an RGB color val """ Color objects are serialized into 'rgb(#, #, #)' notation. """ - def to_representation(self, obj): - return "rgb(%d, %d, %d)" % (obj.red, obj.green, obj.blue) + def to_representation(self, value): + return "rgb(%d, %d, %d)" % (value.red, value.green, value.blue) def to_internal_value(self, data): data = data.strip('rgb(').rstrip(')') @@ -601,16 +601,16 @@ By default field values are treated as mapping to an attribute on the object. I As an example, let's create a field that can be used to represent the class name of the object being serialized: class ClassNameField(serializers.Field): - def get_attribute(self, obj): + def get_attribute(self, instance): # We pass the object instance onto `to_representation`, # not just the field attribute. - return obj + return instance - def to_representation(self, obj): + def to_representation(self, value): """ - Serialize the object's class name. + Serialize the value's class name. """ - return obj.__class__.__name__ + return value.__class__.__name__ ### Raising validation errors @@ -672,10 +672,10 @@ the coordinate pair: class CoordinateField(serializers.Field): - def to_representation(self, obj): + def to_representation(self, value): ret = { - "x": obj.x_coordinate, - "y": obj.y_coordinate + "x": value.x_coordinate, + "y": value.y_coordinate } return ret