[Answer]-Some troubles while converting authors id to User model

1👍

Not sure about the to_python method but since you are looping through the authors_id, there is no need to do

authors.append(get_user(IntField.to_python(self.authors_id[i])))

You should be good with

authors.append(get_user(IntField.to_python(i)))
👤Mikael

0👍

Instead of

IntField.to_python(self.authors_id[i]))

I think you just need to do:

IntField.to_python(i)

In Python the ‘for i in some_list’ construction gives you elements of the list, not integer indexes.

0👍

You said that you were getting this error:

and unbound method to_python() must be called with IntField instance as first argument (got int instance instead)

I got a similar error from MongoEngine. In my case the problem was that I defined the field like this:

foo_id = IntField

The correct way to define it is:

foo_id = IntField()

When I added the parenthesis, the problem went away.

👤Shahaf

Leave a comment