Skip to content

Commit

Permalink
Make method_name optional in SerializerMethodField
Browse files Browse the repository at this point in the history
https://www.django-rest-framework.org/api-guide/fields/#serializermethodfield

You can leave the method_name parameter empty, to get a default value.

For a long time, drf even gave an error when you provided a parameter that matched `get_` your field name:
encode/django-rest-framework#2420
  • Loading branch information
stianjensen committed Mar 31, 2022
1 parent 946c7d6 commit 00858e6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rest_framework-stubs/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ class SerializerMethodField(Field):
method_name: str = ...
def __init__(
self,
method_name: str = ...,
method_name: Optional[str] = ...,
*,
read_only: bool = ...,
write_only: bool = ...,
Expand Down

0 comments on commit 00858e6

Please sign in to comment.