使用以下发布模型,如何在python中编写查询以获取状态设置为 Finished
的所有发布?
relStatus = ("Planning", "Pending Approval", "Assigning Testers", "Testing", "Cancelled", "Finished")
class Release(db.Document):
release_name = db.StringField(max_length=80, required=True)
description = db.StringField(max_length=160, required=True)
start_date = db.DateTimeField(required=True)
end_date = db.DateTimeField(required=True)
status = db.StringField(default="Planning", choices=relStatus)
def __unicode__(self):
return self.release_name
def __repr__(self):
return self.release_name
我正在使用PyMongo作为连接驱动程序。
答案 0 :(得分:1)
您可以使用以下简单查询从mongodb获取结果:
result = mongo.db.collection_name.find({'status':'Finished'},{'_id':False}})
result = list(result)
print(result)