mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Add display value method
Returns the text representation of the instance. Subclasses can override this method to provide a different display value used for populating the `choices` property.
This commit is contained in:
parent
0cbfbc27d8
commit
2f6e5d0509
|
@ -148,7 +148,7 @@ class RelatedField(Field):
|
|||
return OrderedDict([
|
||||
(
|
||||
six.text_type(self.to_representation(item)),
|
||||
six.text_type(item)
|
||||
six.text_type(self.display_value(item))
|
||||
)
|
||||
for item in queryset
|
||||
])
|
||||
|
@ -160,6 +160,9 @@ class RelatedField(Field):
|
|||
def iter_options(self):
|
||||
return iter_options(self.grouped_choices)
|
||||
|
||||
def display_value(self, instance):
|
||||
return six.text_type(instance)
|
||||
|
||||
|
||||
class StringRelatedField(RelatedField):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user