English 中文(简体)
Django-NoRel的带宽模型使“扫描代码”错误
原标题:Saving nested models in Django-NoRel gives "can t encode" error

I can save a "Node", "Link" but not a "Graph" (see error below). Using pymongo 2.1.1, Django-NoRel, Python 2.7:

from django.db import models
from djangotoolbox.fields import SetField, ListField, EmbeddedModelField

class Graph(models.Model):
    links = ListField(EmbeddedModelField( Link ))

class Link(models.Model):
    parent = EmbeddedModelField( Node )
    child = EmbeddedModelField( Node )

class Node(models.Model):
    extent = SetField() # set of strings e.g. "Gene-Bmp4"
    intent = SetField() # set of strings

纽约总部

n1 = Node(extent=set(["Gene-bmp4"]),intent=set(["Attr1", "Attr2"]))
n2 = Node(extent=set(["Gene-fp4"]),intent=set(["Attr3", "Attr4"]))
link = Link(parent=n1, child=n2)
links = [link]
g = Graph(links=links)
g.save()

产生错误:

/Library/Python/2.7/site- Packages/pymongo-2.1.1-py2.7-macosx-10.7-intel.egg/pymongo/ Collection.py:312: 滚动式战斗机:可装条码——重载on器模块并再次尝试。 如果你看不出印瓦文件例外,请见一页。

Exception Type:     InvalidDocument
Exception Value:    Cannot encode object: set([ Attr2 ,  Attr1 ])
Exception Location:     /Library/Python/2.7/site-packages/pymongo-2.1.1-py2.7-macosx-10.7-intel.egg/pymongo/collection.py in insert, line 312

Does anyone has any idea what should I do??

问题回答

看像对我说的。 请在上开放机票。

这里的问题是,你不能把布森定为一类物体,因为布森没有确定类型。

最好的解决办法是,在你去除图表之前,把这套装置封起来。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签