Add help texts to ModelSerializer property fields

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.
This commit is contained in:
Matías Lang 2015-10-30 18:35:52 -03:00
parent 119a073299
commit d1d0a78227

View File

@ -1160,7 +1160,7 @@ class ModelSerializer(Serializer):
Create a read only field for model methods and properties. Create a read only field for model methods and properties.
""" """
field_class = ReadOnlyField field_class = ReadOnlyField
field_kwargs = {} kwargs = {'help_text': getattr(model, field_name).__doc__}
return field_class, field_kwargs return field_class, field_kwargs