概述:
我的用户文档使用FileFields引用图像文档。不能用FileField深入复制对象(为什么?)深入复制用户文档,取消关联的映像(使用FileField),因此失败。
我试图使用MongoEngine (0.7.8)查询一个集合,如果我是这样查询的话:
>>> 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是两个用户文档。下面是事件的外观(顺便说一句,它确实允许继承)。
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数据。不幸的是,这不起作用。
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>https://stackoverflow.com/questions/13906734
复制相似问题