Django 管理员的filter_horizontal(&filter_vertical)不工作
我尝试对 ManyToMany 字段使用 ModelAdmin.filter_horizontal 和 ModelAdmin.filter_vertical 而不是选择多个框,但我得到的是:
我的模型:
class Title(models.Model):
#...
production_companies = models.ManyToManyField(Company, verbose_name="компании-производители")
#...
我的管理员:
class TitleAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("original_name",)}
filter_horizontal = ("production_companies",)
radio_fields = {"state": admin.HORIZONTAL}
#...
javascript 加载正常,我真的不明白发生了什么。 Django 1.1.1 稳定。
I'm trying to use ModelAdmin.filter_horizontal and ModelAdmin.filter_vertical for ManyToMany field instead of select multiple box but all I get is:
My model:
class Title(models.Model):
#...
production_companies = models.ManyToManyField(Company, verbose_name="компании-производители")
#...
My admin:
class TitleAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("original_name",)}
filter_horizontal = ("production_companies",)
radio_fields = {"state": admin.HORIZONTAL}
#...
The javascripts are loading OK, I really don't get what happens. Django 1.1.1 stable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于得到了解决方案。问题在于该字段的详细名称 - 它是 str 而不是 unicode。转向 unicode 有帮助。
谢谢 :-)
I finally got the solution. The problem was with the field's verbose name - it was str instead of unicode. Moving to unicode helped.
Thanks :-)
我也在寻找这样的答案。我刚刚发现“filter_horizontal”的值必须是列表或元组。
所以这段代码:
应该改为:
I was also looking for this kind of answer. I just found out the value of 'filter_horizontal' must be a list or tuple.
So this code:
should be changed to:
filter_horizontal
不起作用的另一个潜在原因是覆盖包含小部件必需的 JavaScript 文件的form.media
属性。Another potential cause for
filter_horizontal
not working is overridingform.media
property that includes the necessary JavaScript files for the widget.