mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
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:
parent
119a073299
commit
d1d0a78227
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user