Skip to content

Commit 7a3d96d

Browse files
authored
Default SerializerMethodField's help_text to the docstring of the method.
1 parent c05998f commit 7a3d96d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

rest_framework/fields.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,11 @@ def bind(self, field_name, parent):
18781878
# The method name defaults to `get_{field_name}`.
18791879
if self.method_name is None:
18801880
self.method_name = 'get_{field_name}'.format(field_name=field_name)
1881+
# If help_text isn't specified, try to get the method's docstring.
1882+
if self.help_text is None:
1883+
method = getattr(parent, self.method_name, None)
1884+
if method is not None:
1885+
self.help_text = method.__doc__
18811886

18821887
super().bind(field_name, parent)
18831888

0 commit comments

Comments
 (0)