| 13 | |
| 14 | |
| 15 | class Book(models.Model): |
| 16 | title = models.CharField(max_length=200, null=False) |
| 17 | author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True) |
| 18 | summary = models.TextField( max_length=1000, help_text='Enter a brief description of the book') |
| 19 | isbn = models.CharField('ISBN', max_length=13, unique=True, help_text='13 Character <a href="https://www.isbn-international.org/content/what-isbn">ISBN number</a>') |
| 20 | genre = models.ManyToManyField( Genre, help_text='Select a genre for this book') |
| 21 | |
| 22 | class Meta: |
| 23 | ordering = ['title', 'author'] |
| 24 | |
| 25 | def __str__(self): |
| 26 | return self.title |
| 27 | |
| 28 | def display_id(self): |
| 29 | return self.id |
| 30 | |
| 31 | def get_absolute_url(self): |
| 32 | return reverse("book_detail", args=[str(self.id)]) |
| 33 | |
| 34 | def display_genre(self): |
| 35 | return ', '.join(genre.name for genre in self.genre.all()[:3]) |
| 36 | |
| 37 | display_genre.short_description = 'Genre' |
| 38 | |
| 39 | |
| 40 | class BookInstance(models.Model): |
nothing calls this directly
no outgoing calls
no test coverage detected