我有mongoalchemy的模型:
class ImportProductReport(mongo.Document):
target = mongo.IntField(default=0)
processed = mongo.IntField(default=0)
is_in_process_remove_offers = mongo.BoolField(default=False)
is_old_offers_removed = mongo.BoolField(default=False)
...
我需要获取记录,其中
ImportProductReport.is_in_process_remove_offers == False,
ImportProductReport.is_old_offers_removed == False,
ImportProductReport.target == ImportProductReport.processed。
没有最后的平等,所有工作都很好:
res = ImportProductReport.query\
.filter(
ImportProductReport.is_old_offers_removed == False,
ImportProductReport.is_in_process_remove_offers == False
)\
.all()
但如果我尝试写这样的东西:
res = ImportProductReport.query\
.filter(
ImportProductReport.is_old_offers_removed == False,
ImportProductReport.is_in_process_remove_offers == False,
ImportProductReport.target == ImportProductReport.processed
)\
.all()
我有一个错误:
AttributeError: 'bool' object has no attribute 'obj'
请告诉我,如何在我的查询中添加最后一个条件? :)
答案 0 :(得分:0)
如果有人帮忙,我找到了问题的答案。 Mongoalchemy允许使用类似于原始MongoDB语法的语法查询。 因此,我需要的查询可以写成如下:
res = ImportProductReport.query\
.filter({
'is_old_offers_removed': False,
'is_in_process_remove_offers': False,
'$where': 'this.target == this.processed'
})\
.all()