1👍
✅
Book and Author is ManyToMany relationship while book can have more then one authors and author can write more then one book. Therefore you need table AuthorBook in which you have records with Book and Author ids
1👍
You should have an intermediary model between author and book:
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
name = models.CharField(max_length=100)
author = models.ManyToManyField(Person, through='AuthorBook')
class AuthorBook(models.Model):
author = models.ForeignKey(Author, on_delete=models.CASCADE)
book = models.ForeignKey(Book, on_delete=models.CASCADE)
👤lch
- [Answered ]-Object has no attribute 'get_notification_display'
- [Answered ]-Django is unable to load angular chunks
- [Answered ]-Python django translation .po and .mo file not translating the files
- [Answered ]-Django 1054, "Unknown column 'emp_id' in 'field list"
Source:stackexchange.com