Use __str__ in relations docs.

REST framework is still compatible with versions of Django that work with Python 2.7, so the docs still need to mention the use of `__unicode__`, but it shouldn't be the default.
This commit is contained in:
Daniel Roseman 2019-02-01 14:42:18 +00:00 committed by Daniel Roseman
parent 63e352586b
commit e31af0aa03

View File

@ -46,12 +46,12 @@ In order to explain the various types of relational fields, we'll use a couple o
unique_together = ('album', 'order') unique_together = ('album', 'order')
ordering = ['order'] ordering = ['order']
def __unicode__(self): def __str__(self):
return '%d: %s' % (self.order, self.title) return '%d: %s' % (self.order, self.title)
## StringRelatedField ## StringRelatedField
`StringRelatedField` may be used to represent the target of the relationship using its `__unicode__` method. `StringRelatedField` may be used to represent the target of the relationship using its `__str__` method.
For example, the following serializer. For example, the following serializer.
@ -510,7 +510,7 @@ For example, given the following model for a tag, which has a generic relationsh
object_id = models.PositiveIntegerField() object_id = models.PositiveIntegerField()
tagged_object = GenericForeignKey('content_type', 'object_id') tagged_object = GenericForeignKey('content_type', 'object_id')
def __unicode__(self): def __str__(self):
return self.tag_name return self.tag_name
And the following two models, which may have associated tags: And the following two models, which may have associated tags: