我无法让unique_with
在MongoEngine中使用ReferenceFields
。我的模型看起来像这样:
class WorkoutSchedule(database.Document):
""" Defines a workout schedule """
user = database.ReferenceField(User)
title = database.StringField(
required=True,
min_length=3,
max_length=30,
unique_with=user)
如果user
和title
相等,我希望文档是唯一的。但是,这引发了一个例外:
TypeError: Error when calling the metaclass bases
'ReferenceField' object is not iterable
是否可以使用unique_with
和ReferenceFields
,还是必须手动解决此问题?
答案 0 :(得分:1)
unique_with (Default: None)
A field name (or list of field names) that when taken together
with this field, will not have two documents in the collection
with the same value.
因此unique_with
必须是basestring
或list
个{1}}字段名称:
basestring