我正在学习 Django,并且已经通过“The Django Book”完成了 Model 的章节,但是没有办法在 ManyToMany 和 ForeignKey 中为以下问题插入值:
在下面这个模型中,我如何插入细节"Author"
和"Publisher"
for book name = "The book"
withpublication-date = "28/10/2013"
插入值后,我如何返回"Author"
并"Publisher"
获取book name = "The book"
class Author(models.Model):
first_name = models.CharField(max_length = 20)
last_name = models.CharField(max_length = 20, blank = True)
email = models.EmailField(blank = True)
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
class Book(models.Model):
title = models.CharField(max_length=100)
publisher = models.ForeignKey(Publisher)
authors = models.ManyToManyField(Author)
publication_date = models.DateField()