django - 向现有的 django Mongoengine 模型添加了新的 bool 字段,但之后无法过滤该字段

标签 django mongodb django-models mongoengine database

首先我的django模型是这样的:

class List(Document):
    owner = ReferenceField('User')
    name = StringField()
    users = ListField(ReferenceField('User'))
    created_at = DateTimeField(default=datetime.datetime.now)

在我添加了一个新的 filed is_cancelled 之后,现在是这样的:

class List(Document):
    owner = ReferenceField('User')
    name = StringField()
    users = ListField(ReferenceField('User'))
    created_at = DateTimeField(default=datetime.datetime.now)
    is_cancelled = BooleanField(default = False)

我将 mongoengine 用于 django mongodb ORM。但是现在当我想进行过滤查询时:

List.objects.filter(is_cancelled=False)
returns []

我使用 django 对象将所有 is_cancelled 字段设置为 False:

for x in List.objects.all():
    x.is_cancelled = False
    x.save()

但是对于上面的查询,我仍然得到一个空列表。 我正在查看 Django 对象的 is_cancelled 文件,我看到 is_cancelled = False

l = List.objects.all()[0]
l.is_cancelled

错误

但是当我从 mongodb shell 看的时候。没有归档为 is_cancelled。

db.list.find()
{ "_cls" : "List", "_id" : ObjectId("4e8451598ebfa80228000000"), "_types" : [ "List" ],     
"created_at" : ISODate("2011-09-29T16:24:28.781Z"), "name" : "listname", "users" : [          
{
            "$ref" : "user",
            "$id" : ObjectId("4e79caf78ebfa80c00000001")
    },      {
            "$ref" : "user",
            "$id" : ObjectId("4e79e4df8ebfa80b64000001")
    },      {
            "$ref" : "user",
            "$id" : ObjectId("4e7aeb898ebfa80b64000001")
    },      {
            "$ref" : "user",
            "$id" : ObjectId("4e79ce028ebfa80c00000004")
    } ] }    

我怎样才能解决这个问题

最佳答案

瞧!

这是我的答案:

https://github.com/hmarr/mongoengine/issues/282

mongengine BooleanField 中存在值为 False 的错误。

但是他们已经用这个补丁修复了它:

https://github.com/hmarr/mongoengine/pull/283

关于django - 向现有的 django Mongoengine 模型添加了新的 bool 字段,但之后无法过滤该字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598632/

相关文章:

python - 使用 mod_wsgi 在 Apache 上部署 django 应用程序

python - 使用 django cleaned data pop 在提交到 db 之前删除数据

javascript - 如何在我的 Mongoose 模型实例中循环遍历这个数组?

node.js - 将 geoNear 查询与另一个值查询结合起来

mongodb - GORM 在 Grails 中使用 MongoDB 按 ID 获取/查找资源

Django - 在没有 {% load .. %} 的情况下,通过自定义标签替换整个站点的内置模板标签

Django 错误 (13, 'Permission denied')

django - 如何从其他表获取数据,例如序列化器类 django-rest-framework 中的左连接

postgresql - postgres 中索引的默认表空间

python - Django- limit_choices_to 使用 2 个不同的表