如何在 django 中找到"ObjectId" mongodb 的田地?



我正在寻找通过"ObjectId"获取字段的方法

但是,我没有找到。

I declare Entries model

class Entries(models.Model):
    subject = models.CharField(max_length=120, null=False)
    content = models.TextField(null=False)
    created = models.DateTimeField(auto_now_add=True, auto_now=True)
    writer = models.CharField(max_length=30, null=False)

@csrf_exempt
def viewPost(request, entry_number): # ex) entry_number = '513c780210ae920f58762d3d'
    e = Entries.objects.get(id = entry_number) # error!!
    return HttpResponse('zz')

it code引发错误,因此我尝试under codes.

e = Entries.objects.get(_id = entry_number) # error!!
e = Entries.objects.get(pk = entry_number) # error!!
e = Entries.objects.get(id = entry_number) # error!!
e = Entries.objects.get(_id = ObjectId(entry_number)) # error!!
e = Entries.objects.get(pk = ObjectId(entry_number)) # error!!
e = Entries.objects.get(id = ObjectId(entry_number)) # error!!
e = Entries.objects(id = entry_number) # error!!

显示消息

'invalid literal for int() with base 10: '513c780210ae920f58762d3d', ...

因此,现在我使用pymongo(没有django的ORM)

d = entries_table.find_one({'_id' : ObjectId(entry_number)})
return render_to_response('view.html', {'ROOT_URL':ROOT_URL,
                                        'entry':d, 'id':d['_id']})

谁来帮我用一下

Django ORM现在不支持MongoDB。请使用PyMongo。

相关内容

  • 没有找到相关文章

最新更新