“布尔”对象没有属性“has_header”;通过我的管理员中的文件字段上传时

发布于 2024-10-25 03:10:22 字数 1155 浏览 2 评论 0原文

我的 models.py

from django.db import models
from django.contrib.auth.models import User

class Song(models.Model):
   uploader = models.ForeignKey(User)
   date_uploaded = models.DateTimeField(auto_now=True)

   song_file = models.FileField(upload_to='music/', max_length=100)
   artist = models.CharField(max_length=75, blank=True)
   title = models.CharField(max_length=100, blank=True)
   genre = models.CharField(max_length=100, blank=True)

   def __unicode__(self):
      return u'%s' % (self.song_file)

我的 admin.py

from django.contrib import admin
from uploader.models import Song
from django.db import models


class SongAdmin(admin.ModelAdmin):

   list_display = ('song_file', 'title', 'artist', 'genre', 'uploader')

   search_fields = ('song_file', 'uploader', 'genre', 'title')
   fields = ('song_file', 'title', 'artist', 'genre')

admin.site.register(Song, SongAdmin)

文件已上传(我在媒体文件夹中看到它),但它没有显示在我的管理页面中,当文件上传时,我得到:

'bool' object has no attribute 'has_header' when uploading via a FileField in my admin

我在这里遗漏了一些明显的东西吗?对 django 来说还很陌生。

My models.py

from django.db import models
from django.contrib.auth.models import User

class Song(models.Model):
   uploader = models.ForeignKey(User)
   date_uploaded = models.DateTimeField(auto_now=True)

   song_file = models.FileField(upload_to='music/', max_length=100)
   artist = models.CharField(max_length=75, blank=True)
   title = models.CharField(max_length=100, blank=True)
   genre = models.CharField(max_length=100, blank=True)

   def __unicode__(self):
      return u'%s' % (self.song_file)

My admin.py

from django.contrib import admin
from uploader.models import Song
from django.db import models


class SongAdmin(admin.ModelAdmin):

   list_display = ('song_file', 'title', 'artist', 'genre', 'uploader')

   search_fields = ('song_file', 'uploader', 'genre', 'title')
   fields = ('song_file', 'title', 'artist', 'genre')

admin.site.register(Song, SongAdmin)

The file gets uploaded (I see it in my media folder) but it doesnt display in my admin page and when the file does get uploaded I get:

'bool' object has no attribute 'has_header' when uploading via a FileField in my admin

Am I missing something obvious here? Pretty new to django.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2024-11-01 03:10:22

事实证明这是 Pinax 的问题。更新到最新的 git,现在一切正常了!

Turns out it was an issue with Pinax. Updated to the latest git and everything works now!

遗心遗梦遗幸福 2024-11-01 03:10:22

像这样注释掉该中间件,可能应该将该中间件保留在非调试环境中

    "pinax.middleware.security.HideSensistiveFieldsMiddleware",
+#    "pinax.middleware.security.HideSensistiveFieldsMiddleware",

在网络上的其他地方找到了这个,问题出在 HideSensitiveFieldsMiddleware 中,解决它的方法(用于调试)是在设置文件中

Found this somewhere else on the net, the problem is in the HideSensitiveFieldsMiddleware and the way to work around it (for debug) is to just comment out that middleware like so

    "pinax.middleware.security.HideSensistiveFieldsMiddleware",
+#    "pinax.middleware.security.HideSensistiveFieldsMiddleware",

in your settings file, probably should leave that middleware in for non debug environments

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文