首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MongoEngine GenericReferenceField高级查询

MongoEngine GenericReferenceField高级查询
EN

Stack Overflow用户
提问于 2012-12-16 23:58:41
回答 1查看 989关注 0票数 0

概述:

我的用户文档使用FileFields引用图像文档。不能用FileField深入复制对象(为什么?)深入复制用户文档,取消关联的映像(使用FileField),因此失败。

我试图使用MongoEngine (0.7.8)查询一个集合,如果我是这样查询的话:

代码语言:javascript
复制
    >>> cls.objects(Q(author=devin_user))
    [<FollowUserEvent: [<User: Devin> => <User: Strike>]>]
    # Querying author works fine

    >>> cls.objects(Q(parent=strike_user))
    [<FollowUserEvent: [<User: Devin> => <User: Strike>]>]
    # Querying parent works fine

    >>> cls.objects(Q(parent=strike_user) & Q(author=devin_user))
    *** TypeError: 'Collection' object is not callable. If you meant to call the '__deepcopy__' method on a 'Collection' object it is failing because no such method exists.
    # Definitely fails here, but why?


    # Even stranger, if I combine a query on parent and hidden_at it succeeds, but if I combine a query on author and hidden_at it gloriously fails
    >>> cls.objects(Q(parent=strike_user) & Q(hidden_at=None))
    [<FollowUserEvent: [<User: Devin> => <User: Strike>]>]
    # Querying parent works fine

    >>> cls.objects(Q(author=devin_user) & Q(hidden_at=None))
    *** TypeError: 'Collection' object is not callable. If you meant to call the '__deepcopy__' method on a 'Collection' object it is failing because no such method exists.
    # Boom!

strike_user和devin_user是两个用户文档。下面是事件的外观(顺便说一句,它确实允许继承)。

代码语言:javascript
复制
    class Event(Document):                                             
       """                                                            
       :param anti: tells if an event is related to an inverse event  
           e.g. follow/unfollow, favorite/unfavorite                  
       :param partner: relates an anti-event to an event.             
           only set on the undoing event                              
       """                                                            
       author = GenericReferenceField(required=True)                  
       parent = GenericReferenceField(required=True)                  
       created_at = DateTimeField(required=True, default=datetime.now)
       hidden_at = DateTimeField()                                    

       anti = BooleanField(default=False)                             
       partner = ReferenceField('Event', dbref=False)                 
       meta = {                                                       
           'cascade': False,                                          
           'allow_inheritance': True }

       def __repr__(self):
           action = "=/>" if self.anti else "=>"
           return "<%s: [%s %s %s]>" % (self.__class__.__name__,
               self.author.__repr__(), action, self.parent.__repr__())

对我来说好像是个窃听器,但我很想听到反馈:)

更新:

看起来mongoengine/queryset.py:98调用copy.deepcopy。它遵循一个ReferenceField,并试图复制它的FileField数据。不幸的是,这不起作用。

代码语言:javascript
复制
    Class Image(Document):
        file = FileField(required=True)

    Class User(Document):
        name = StringField()
        image = ReferenceField('Image')

    >>> copy.deepcopy(user)
    *** TypeError: 'Collection' object is not callable. If ...

    >>> user.image = None
    >>> copy.deepcopy(user)
    <User: Devin>
EN

回答 1

Stack Overflow用户

发布于 2012-12-17 19:34:27

原来,这是个虫子!我在概述中所说的是正确的。[臭虫的状态

有用的链接:

bug的状态

邮件列表讨论

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13906734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档