尝试使用FileField通过GridFS将视频上传到Django管理员时出错

时间:2015-01-19 22:27:32

标签: python django mongodb

当我上传文件并尝试将其保存在管理员中时,我收到以下错误,

__str__() takes no arguments (1 given)

我不确定这是否是由于我对FileFields做了什么。我正在做的另一件事是我有一个"评论"同一个对象中的字段,但我不在admin中显示它。

我的相关代码如下来自models.py,

class Video(models.Model):
    pub_date = models.DateTimeField(auto_now_add=True, null=True)
    title = models.CharField(max_length=255)
    caption = models.TextField(null=True)
    video = models.FileField(storage=gridfs_storage, upload_to='videos/%Y/%m/%d')
    tags = CategoryField()
    comments = CategoryField(EmbedOverrideField('Comment'))

在admin.py中,我执行以下操作,

class VideoAdmin(admin.ModelAdmin):
    list_display = ('pub_date', 'title', 'caption', 'video', 'tags')
    exclude = ('comments',)

site.register(Video, VideoAdmin)
site.register(Comment)

可能导致此错误的原因是什么?

谢谢!

这里是追溯,

Traceback:
File "/Users/Anupa/myproject/lib/python2.7/site-     packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request,   *callback_args,   **callback_kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-  packages/django/contrib/admin/options.py" in wrapper
  466.                 return self.admin_site.admin_view(view)(*args,   **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-  packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-  packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  29.             return bound_func(*args, **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  25.                 return func(self, *args2, **kwargs2)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/db/transaction.py" in inner
  371.                 return func(*args, **kwargs)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
  1167.                 self.log_addition(request, new_object)
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/contrib/admin/options.py" in log_addition
  633.             object_repr=force_text(object),
File "/Users/Anupa/myproject/lib/python2.7/site-packages/django/utils/encoding.py" in force_text
  108.                     s = six.text_type(bytes(s), encoding, errors)

Exception Type: TypeError at /admin/website/video/add/
Exception Value: __str__() takes no arguments (1 given)

0 个答案:

没有答案