Reputation: 3923
I'm trying to get MongoEngine with the Flask-Mongoengine extension working, however whenever I use a ListField I get the error below:
if field.field.choices:
AttributeError: 'NoneType' object has no attribute 'choices'
Here is my code:
class Business(db.Document):
name = db.StringField(required=True)
address = db.StringField()
location = db.GeoPointField()
tags = db.ListField()
area = db.ReferenceField(Area, dbref=True)
contact = db.EmbeddedDocumentField(Contact)
details = db.EmbeddedDocumentField(details)
Upvotes: 2
Views: 2891
Reputation: 2000
I faced the same issue but for the DictField while update. I was trying to save file name as lable and the details of the as its value object e.g. The class structure is
class Folder(Document):
name = StringField(required=True)
fileList = DictField()
class File(EmbeddedDocument):
name = StringField(required=True)
size = IntField()
...
fld = Folder(name="fld1")
fl = File(name="fl1.txt",size=10)
fld.fileList["fl1.txt"] = fl
It was working while save but failing when I tried to update the record.
After couple of permutation, I realized that "." in lable used for assigning file object to fileList was problem. Below change in the last line of code worked
fld.fileList["fl1_txt"] = fl
Upvotes: 0
Reputation: 929
I had the same problem. What fixed it for me was passing a Field object to the ListField()
call in the ListField
declarations, example:
tags = db.ListField(db.StringField())
Upvotes: 3