Archive for November, 2010

  1. Django Select Multiple filter.

    Django has a really nice select multiple field, for choosing multiple items at once with a Javascript chooser..

    It is really handy to use when there is a large number of items that have to be chosen from in a select. I am using with JQuery.

    To do this, grab SelectFilter2.js from the django-admin media folder, or get it from Django’s GitHub repository. Then to initialize it you can put the following into your code:

    $(document).ready(function() {
        $.each($("select[multiple]"), function () {
             // "Locations" can be any label you want
        SelectFilter.init(this.id, "Locations", 0, "/media/");
      });
     });

    This will use the SelectFilter on all select multiples and give it a label of locations.

    For reference the functions are:

     function(field_id, field_name, is_stacked, admin_media_prefix)

    So you could use:

     SelectFilter.init("#MySelect", "Test", 0, "{{ MEDIA_URL}}img/");

    Then all that needs is styling the select multiple.

    By timc3 on the
    November 2nd, 2010