> class Artist(models.Model): > name = models.CharField(maxlength=100) > > class Song(models.Model): > title = models.CharField(maxlength=100) > artists = models.ManyToManyField(Artist) > > > I would like to join the artists that are related to a > particular song into a string (comma separated) in the __str__ > of the song. Join doesn't work properly because it is a > ManyToManyManager object being returned by self.artists in the > Song class. Is there some way to make these individual Artist > records into strings so I can join them?
Does the following work? def __str__(self): return "%s (%s)" % ( self.title, '/'.join(self.artists) ) This assumes that an Artist has a __str__ method as well. If not, you could change that one line to '/'.join([artist.name for artist in self.artists]) -tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---