首先我的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 的错误。
但是他们已经用这个补丁修复了它:
关于django - 向现有的 django Mongoengine 模型添加了新的 bool 字段,但之后无法过滤该字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598632/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr