django-models - 书籍、个人资料和作者之间的关系在 Django 中是否正确
问题描述
我创建了 3 个表配置文件、作者和书籍。这三个表之间的关系在Django中是否正确。
从 django.db 导入模型
# It is a user profile
class Profile(models.Model):
username = models.CharField(max_length=250)
firstname = models.CharField(max_lenght=250)
lastname = models.CharField(max_length=250)
useremail = models.EmailField()
def __str__(self):
return self.username
# It is a author table
class Author(models.Model):
authorname = models.CharField(max_length=250)
authoremail = models.EmailField()
authormobile = models.IntegerField()
authoraffliation = models.CharField(max_length=250)
def __str__(self):
return self.authorname
# It is a book database
class Book(models.Model):
bookname = models.CharField(max_length=250)
bookuser = models.ForeignKey(Profile)
bookauthor = models.ManyToManyField(Author)
publisher = models.CharField(max_length=250)
published_year = models.DateField()
isbn_number = models.CharField(max_length=250)
# The __str__ method just tells django what to print when it need to print out an instance of Book model
def __str__(self):
return self.bookname
解决方案
推荐阅读
- javascript - 单击按钮时,React setState 不会自动填充数据
- javascript - 在同一个视口中加载多个 obj 元素
- sql - Update primary key value along with foreign keys?
- javascript - 通过异步方法可以使用 _.sumBy
- mysql - 使用 2 个连接创建视图时出现问题
- javascript - 运行 Angular 8 生产时:在严格模式下删除不合格的标识符
- javascript - Angular主js文件被截断?
- flutter - How to make widget out of a GestureDetector with a Container child?
- java - 具有相同类的多个@ConfigurationProperties
- mongodb - 更新文档内的嵌套集合 - MongoDB