Django: int() argument must be a string or a number, not 'ObjectId'

527 Views Asked by At

When testing my connection to MongoDB I put the following in my models.py. I had to change some parts of it (JSONField) because I'm using newer version of Django 1.8.7 which seems to have made it not work:

from django.db import models
from jsonfield import JSONField

class Post(models.Model):
    title = models.CharField(max_length=200)
    text = models.TextField()
    tags = JSONField()
    comments = JSONField()

Then I run:

from testapp.models import Post
post = Post.objects.create(
    title='Hello MongoDB!',
    text='Just wanted to drop a note from Django. Cya!',
    tags=['mongodb', 'django']
)
post.comments = []
post.comments.extend(['Great post!', 'Please, do more of these!'])
post.save()

The last line of the script results in an error:

TypeError: int() argument must be a string or a number, not 'ObjectId'

My config: Django 1.8.7, Python 2.7, Django-nonrel 1.6, django-mongodb-engine 0.6.0

0

There are 0 best solutions below