Why StringRelatedField is read_only? #8203
Answered
by
tomchristie
weber-s
asked this question in
Question & Answer
-
Hello ! I wonder why a class StringRelatedField(RelatedField):
"""
A read only field that represents its targets using their
plain string representation.
"""
def __init__(self, **kwargs):
kwargs['read_only'] = True
super().__init__(**kwargs)
def to_representation(self, value):
return str(value) but why? I needed to empty one StringRelatedField, and the solution was to go back to a ForeignKeyRelatedField, which ok for the update, but "ugly" for the get... |
Beta Was this translation helpful? Give feedback.
Answered by
tomchristie
Oct 6, 2021
Replies: 1 comment 1 reply
-
Because there's no way to take a string, and lookup which instance would return that string. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
weber-s
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because there's no way to take a string, and lookup which instance would return that string.