Updated example models to use __str__ in relations docs. (#6433)

This commit is contained in:
Daniel Roseman 2019-02-01 18:50:27 +00:00 committed by Carlton Gibson
parent 63e352586b
commit 7310411533

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: