From d1d0a78227a9eb44bf0a9a9bd520f7505f34641e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Lang?= Date: Fri, 30 Oct 2015 18:35:52 -0300 Subject: [PATCH] Add help texts to ModelSerializer property fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a field of a model wich is a read-only property is included in a ModelSerializer, automátically set its help text to the docstring of the property function. I used this to work with the documentation tool django-rest-swagger. --- rest_framework/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 35fb8fcf0..4e52f4aac 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -1160,7 +1160,7 @@ class ModelSerializer(Serializer): Create a read only field for model methods and properties. """ field_class = ReadOnlyField - field_kwargs = {} + kwargs = {'help_text': getattr(model, field_name).__doc__} return field_class, field_kwargs