django-mongodb:检索一个给出错误的对象

时间:2014-04-02 17:15:16

标签: django mongodb django-mongodb-engine

我使用django_mongo_engine(0.4.0)作为django应用程序的支持。

使用like

创建Instructor对象
inst = Instructor.objects.create(
        email=request.POST.get('email').lower(),
        password = set_password(request.POST.get('password')),
        title=request.POST.get('title'),
        first_name=request.POST.get('first_name'),
        last_name=request.POST.get('last_name'))

request.session['inst_id'] = inst.id

在mongo shell中, inst.id 似乎是 ObjectId(u' 533c3b0c9b0dbb416e000000')

在调试模式下(pdb)

Instructor.objects.all()[0].id 

将提供 id u'533c3b0c9b0dbb416e000000'

检索讲师对象时出错:

 Instructor.objects.get(id=request.session['inst_id'])

ValueError:对于带有基数为10的int()的无效文字:' 533c40a99b0dbb42d9000000'

instructor2 = Instructor.objects.get(id=ObjectId(request.session['inst_id']))

TypeError :int()参数必须是字符串或数字,而不是' ObjectId'

instructor3 = Instructor.objects.get(id=str(request.session['inst_id']))

ValueError:对于带有基数为10的int()的无效文字:' 533c40a99b0dbb42d9000000'

有任何线索吗?

0 个答案:

没有答案