【发布时间】:2014-04-11 21:00:12
【问题描述】:
我正在尝试使用 django + mongodb 编写一个简单的文件上传应用程序。我已经正确设置了我的 SITE_ID(我正在写入数据库)。
使用管理页面,我可以上传文件(文件出现在目录结构中),但是当我点击文件名时:
它给了我这个错误:
DatabaseError at /admin/myapp/fileUpload/534855062da57ae6ecc4399f/myapp/files/1_2.jpg/
AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u'534855062d...' instead).
这是我正在使用的代码:
models.py
class fileUpload(models.Model):
some_file_location = models.FileField(upload_to='myapp/files/')
admin.py
admin.site.register(fileUpload)
数据库条目:
db.myapp_fileupload.find() { "_id" : ObjectId("53484e4e2da57ad214df5072"), "some_file_location" : "myapp/files/1.jpg" }
【问题讨论】: