class Author (models.Model):
name = models.CharField (max_length = 255)
born = models.DateField (null = True, blank = True)
died = models.DateField (null = True, blank = True)
bio = models.TextField (null = True, blank = True)
def __unicode__ (self):
return self.name
class Meta:
ordering = ["name"]
class Book (models.Model):
name = models.CharField (max_length = 255)
date = models.DateField ()
authors = models.ManyToManyField (Author, related_name = "books")
description = models.TextField (null = True, blank = True)
def __unicode__ (self):
authors = [author.name for author in self.authors.all ()]
return ", ".join (authors) + ": " + self.name
class Meta:
ordering = ["name", "date"]