2013-12-17 35 views
2

我试图让下面的查询:AttributeError的:“布尔”对象在Peewee没有属性“克隆”的SQLite

ignored = Activity.select().join(StuActIgnore).join(Student).where(Student.id == current_user.id) 
Activity.select().where(~(Activity.name**"%BBP") & Activity not in ignored) 

这不会给我任何错误,但以下任何一项:

Activity.get(~(Activity.name**"%BBP") & Activity not in ignored) 
Activity.select().where(~(Activity.name**"%BBP") & Activity not in ignored).join(Course) 

给了我以下错误:

AttributeError: 'bool' object has no attribute 'clone' 

如果我试试这个:

Activity.select().join(Course).join(StuCouRel).join(Student).where(~(Activity.name**"%BBP") & Activity not in ignored & Student.id == current_user.id) 

它会告诉我说:

TypeError: argument of type 'Expression' is not iterable 

我觉得这是非常令人困惑,因为这个:

already_selected = Course.select().join(StuCouRel).join(Student).where(Student.id == current_user.id) 
to_choose = Course.select().where(Course not in already_selected) 

工作完全正常,而这是非常类似于我想要看来。

我完全不知道这可能意味着什么,我在文档中找不到任何东西。 'bool'对象可能代表布尔值,但我看不到我的查询结果是一个布尔值。我也不知道'克隆'是什么意思,我也不知道如何解决这个错误。

回答

2

Python将任何形状的信息投给__contains__()返回一个布尔值。这就是为什么在构建peewee查询时不能使用“not in”或“in”。您改为使用<<来表示“IN”。

您可以试试:

ignored = (Activity 
      .select() 
      .join(StuActIgnore) 
      .join(Student) 
      .where(Student.id == current_user.id)) 
Activity.select().where(~(Activity.name**"%BBP") & ~(Activity.id << ignored)) 

参见查询更多信息的文档http://peewee.readthedocs.org/en/latest/peewee/querying.html#column-lookups

+3

也有一个疑难杂症我倾向于现在,然后打每一个;忘记在等价性检查中提供模型属性..即做Account.get(name == name)而不是Account.get(Account.name == name)。 第一段代码结束查询“..FROM”帐户“AS t1 WHERE?[True]”,并且在此处失败https://github.com/coleifer/peewee/blob/2.6.1/peewee.py #L2252与 “AttributeError:'bool'对象没有属性'clone'” 它会很好,如果它会在提醒语法中包装异常。 :) – stt

+0

@stt照顾做出答案? – grandchild

相关问题