【问题标题】:Nested Classes in Python (PeeWee models)Python 中的嵌套类(PeeWee 模型)
【发布时间】:2013-07-08 08:38:13
【问题描述】:

我在搜索示例 python 代码时遇到了一个示例:

import peewee
from peewee import *

db = MySQLDatabase('jonhydb', user='john',passwd='megajonhy')

class Book(peewee.Model):
    author = peewee.CharField()
    title = peewee.TextField()

    class Meta:
        database = db

我最多可以理解title = peewee.TextField(),但我对class Meta: ... 行有点困惑。为什么需要这个?难道没有其他方法可以建立连接吗?

【问题讨论】:

标签: python


【解决方案1】:

这是Peewee ORM 指定应该使用哪些数据库连接模型类的方式。它在子类中指定,因此 Peewee 不会将其视为模型字段。有关更多详细信息,请参阅涵盖 Database and Connection recipes 的 Peewee 食谱文章。

【讨论】:

猜你喜欢
  • 2021-04-30
  • 2021-01-06
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
  • 2016-05-07
  • 2011-03-26
  • 1970-01-01
  • 2018-12-08
相关资源
最近更新 更多