基本上是这样的
ValidationError (MatterUser:51dc53babc6163617b38c2fe) (A ReferenceField only accepts DBRef or documents 1.A ReferenceField only accepts DBRef or documents 2.A ReferenceField only accepts DBRef or documents 3.A ReferenceField only accepts DBRef or documents 4.A ReferenceField only accepts DBRef or documents 5.A ReferenceField only accepts DBRef or documents 6.A ReferenceField only accepts DBRef or documents 7.A ReferenceField only accepts DBRef or documents 8.A ReferenceField only accepts DBRef or documents 9.A ReferenceField only accepts DBRef or documents 10.A ReferenceField only accepts DBRef or documents 11.A ReferenceField only accepts DBRef or documents 12.A ReferenceField only accepts DBRef or documents 13.A ReferenceField only accepts DBRef or documents 14.A ReferenceField only accepts DBRef or documents 15.A ReferenceField only accepts DBRef or documents 16.A ReferenceField only accepts DBRef or documents: ['groups'])
我的模型似乎正确(仅显示相关位)
class MatterUser(Document):
groups = ListField(ReferenceField('Grouping'))
homeGroup = ReferenceField('Grouping')
...
class PermissionHolder(Document):
meta = {'allow_inheritance': True}
...
class Grouping(PermissionHolder):
...
视图中的调用就像
def createGroup(info):
group = Grouping()
group.save()
info['owner'].groups+=group
info['owner'].save() # The offending line
...
newUser = MatterUser(...)
newUser.save()
info = {'owner': newUser,...}
newUser.homeGroup = createGroup(info)
我不明白为什么我会收到如此多的验证错误,甚至是问题所在。
编辑:我还意识到给出的错误等于模型中的字段数,即 ReferenceField。在这种情况下,分组有 16 个字段