我在看
from django.db import models
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 Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
这是一个来自 djangobook.com 的示例,我对 models.Model 参数感到困惑。我知道模型是一个具有诸如 CharField() 之类的方法的类,它被继承到这些类中以创建表列……对吗?但是模型的“模型”部分在哪里出现?这是为了什么?哪里需要?
任何来自您的类比或解释将不胜感激,因为我一直在互联网上寻找并且仍然感到困惑。对不起,无知的措辞问题。
谢谢!