Django admin's filter_horizontal (& filter_vertical) not working
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.
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 :-)
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:
filter_horizontal = ("production_companies",)
should be changed to:
filter_horizontal = ("production_companies", "production_companies")
Another potential cause for filter_horizontal
not working is overriding form.media
property that includes the necessary JavaScript files for the widget.
精彩评论