Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Admin + Filter Horizontal?

I've added filter horizontal

filter_horizontal = ('blocked_email_notifications',)

To my ModelAdmin, but it's still rendering it as a multiple select widget, rather than the nifty javascript enhanced version. How come? Do I need to add something else?

The user model has it defined as

blocked_email_notifications = ManyToManyField('EmailTemplate', blank=True)

And the form has it defined as

blocked_email_notifications = ModelMultipleChoiceField(queryset=EmailTemplate.objects.order_by('key'), required=False)
like image 875
mpen Avatar asked Sep 01 '10 06:09

mpen


1 Answers

If you define the field in the form you need to include the widget:

from django.contrib.admin.widgets import FilteredSelectMultiple

blocked_email_notifications = ModelMultipleChoiceField(
    queryset=EmailTemplate.objects.order_by('key'), 
    required=False,
    widget=FilteredSelectMultiple(
        verbose_name=EmailTemplate._meta.verbose_name,
        is_stacked=False))

is_stacked:

  • False: the lists are rendered side by side
  • True: the lists are rendered one underneath the other
like image 150
Bernhard Vallant Avatar answered Sep 26 '22 23:09

Bernhard Vallant