1👍
Ugh, finally figured it out. Because of how mongoengine refers to documents and the way python handles += when adding things to a list it basically tried to add every single field to the list.
When I changed it to
info['owner'].groups.append(group)
It performed the intended behavior and was error free
1👍
In python doing a +=
to a list requires the item you are adding to be iterable. Then each individual item will be appended to the list.
In MongoEngine Documents and EmbeddedDocuments are iterable and return the field names eg:
class Participant(EmbeddedDocument):
first_name = StringField()
last_name = StringField()
participant = Participant(first_name="Ross", last_name="Lawley")
You can now unpack the document into variables for the field name eg:
field1_name, field2_name = participant
That is why you are getting the validation error +=
is adding each field name to the groups
list. You are correct in what you really want to do is append a single item to your list eg:
info['owner'].groups.append(group)
👤Ross
- [Answered ]-CherryPy with Cheetah as plugin + tool – blank pages
- [Answered ]-Django/Taggit Searching for posts when all tags and title are contained in the database
- [Answered ]-KeyError: Django Losing Session Data Between CBV Redirects
Source:stackexchange.com