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:
James Beith 2015-08-10 11:03:57 +01:00
parent 0cbfbc27d8
commit 2f6e5d0509

View File

@ -148,7 +148,7 @@ class RelatedField(Field):
return OrderedDict([ return OrderedDict([
( (
six.text_type(self.to_representation(item)), six.text_type(self.to_representation(item)),
six.text_type(item) six.text_type(self.display_value(item))
) )
for item in queryset for item in queryset
]) ])
@ -160,6 +160,9 @@ class RelatedField(Field):
def iter_options(self): def iter_options(self):
return iter_options(self.grouped_choices) return iter_options(self.grouped_choices)
def display_value(self, instance):
return six.text_type(instance)
class StringRelatedField(RelatedField): class StringRelatedField(RelatedField):
""" """