mongedb 上的 Django-nonrel 列表字段查找
从下面 mongodb 的示例中,首选的查找方式是什么:
from djangotoolbox.fields import ListField, EmbeddedModelField
class Post(models.Model):
...
comments = ListField(models.ForeignKey(Comment, related_name="post", null=True, blank=True), null=True, blank=True)
class Comment(models.Model):
text = models.TextField()
created_on = models.DateTimeField()
post_id = 4eaa636b600998598c000018
以下任一方法都不起作用:
posts = post.objects.filter(comments =('text', 'test'))
posts = post.objects.filter(comments =('pk', post_id))
posts = post.objects.filter(comments =('in', post_id))
From the below example on mongodb, what would be preferred way for lookup:
from djangotoolbox.fields import ListField, EmbeddedModelField
class Post(models.Model):
...
comments = ListField(models.ForeignKey(Comment, related_name="post", null=True, blank=True), null=True, blank=True)
class Comment(models.Model):
text = models.TextField()
created_on = models.DateTimeField()
post_id = 4eaa636b600998598c000018
Neither one of following works:
posts = post.objects.filter(comments =('text', 'test'))
posts = post.objects.filter(comments =('pk', post_id))
posts = post.objects.filter(comments =('in', post_id))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,ListField 中几乎不支持外键。
但是,我现在正在努力改变这一点: https://bitbucket.org/emperorcezar/djangotoolbox
到目前为止,我已经可以插入对象了。 post = Post(comments = [comment_obj]) 现在正在进行查找。
希望如果我能让它工作并且我的拉取请求被接受,这将很快得到支持。
Right now there is little support for a ForeignKey in a ListField.
But, I'm working on changing this right now: https://bitbucket.org/emperorcezar/djangotoolbox
So far I have inserting objects working. post = Post(comments = [comment_obj]) and am working on lookups right now.
Hopefully this will be supported soon if I can get it working and my pull request is accepted.