【问题标题】:PeeWee model has no 'select' attribute errorPeeWee 模型没有“选择”属性错误
【发布时间】:2019-09-25 21:15:31
【问题描述】:

我正在为我正在处理的涉及 Python 3、peewee 和(目前)Sqlite3 的个人项目创建应用程序。我主要导入了 2 个模型类(学生和课程),它们是我创建的基本模型类的子类。

位于 main.py 中的导入语句:

from models.course import Course
from models.student import Student

models/BaseModel.py

from peewee import *

db = SqliteDatabase('database/attendance.db')


class BaseModel:

    class Meta:
        database = db

models/course.py

from peewee import *
from models.basemodel import BaseModel


class Course(BaseModel):
    cid = PrimaryKeyField()
    title = TextField()
    active = BooleanField()

    class Meta:
        table_name = 'courses'

当我尝试进行简单查询以检索课程时,我收到一条错误消息。

查询示例:

active_courses = Course.select().where(Course.active == True)

我收到的错误信息是:

AttributeError: type object 'Course' has no attribute 'select'

【问题讨论】:

    标签: python-3.x peewee


    【解决方案1】:

    您的 BaseModel 类需要扩展 peewee.Model:

    class BaseModel(peewee.Model):
        ...
    

    【讨论】:

    • 谢谢。这就是我在凌晨 3 点进行编码的结果。只见树木不见森林。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 2017-09-20
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    相关资源
    最近更新 更多